1 #pragma once 2 3 /* 4 * Copyright (C) 2017 The Android Open Source Project 5 * 6 * Licensed under the Apache License, Version 2.0 (the "License"); 7 * you may not use this file except in compliance with the License. 8 * You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 */ 18 19 #include <stdlib.h> 20 #include <atomic> 21 22 #include "common/vsoc/shm/base.h" 23 24 namespace vsoc { 25 26 /** 27 * Interface that defines signaling and waiting for signal. 28 */ 29 class RegionSignalingInterface { 30 public: 31 virtual ~RegionSignalingInterface(){}; 32 33 // Post a signal to the guest, the host, or both. 34 // See futex(2) FUTEX_WAKE for details. 35 // 36 // sides_to_signal: controls where the signal is sent 37 // 38 // signal_addr: the memory location to signal. Must be within the region. 39 virtual void SendSignal(layout::Sides sides_to_signal, 40 std::atomic<uint32_t>* signal_addr) = 0; 41 42 // This implements the following: 43 // if (*signal_addr == last_observed_value) 44 // wait_for_signal_at(signal_addr); 45 // 46 // Note: the caller still needs to check the value at signal_addr because 47 // this function may return early for reasons that are implementation-defined. 48 // See futex(2) FUTEX_WAIT for details. 49 // 50 // signal_addr: the memory that will be signaled. Must be within the region. 51 // 52 // last_observed_value: the value that motivated the calling code to wait. 53 // 54 // The return values are: 55 // -1 on failure 56 // 0 indicates success with no tuning information 57 // >0 indicates success. The number indicates how many times the thread 58 // woke before it could return. 59 // Large values indicate that the regions should be tuned. 60 virtual int WaitForSignal(std::atomic<uint32_t>* signal_addr, 61 uint32_t last_observed_value) = 0; 62 }; 63 64 } // namespace vsoc 65