| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 |
| 11 | #ifndef RTC_BASE_EVENT_H_ |
| 12 | #define RTC_BASE_EVENT_H_ |
| 13 |
| 14 | #if defined(WEBRTC_WIN) |
| 15 | #include <WinSock2.h> |
| 16 | #include <windows.h> |
| 17 | #elif defined(WEBRTC_POSIX) |
| 18 | #include <pthread.h> |
| 19 | #else |
| 20 | #error "Must define either WEBRTC_WIN or WEBRTC_POSIX." |
| 21 | #endif |
| 22 |
| 23 | namespace rtc |
| 24 | { |
| 25 |
| 26 | class Event |
| 27 | { |
| 28 | public: |
| 29 | static const int kForever = -1; |
| 30 |
| 31 | Event(); |
| 32 | Event(bool manual_reset, bool initially_signaled); |
| 33 | Event(const Event&) = delete; |
| 34 | Event& operator=(const Event&) = delete; |
| 35 | ~Event(); |
| 36 |
| 37 | void Set(); |
| 38 | void Reset(); |
| 39 |
| 40 | // Wait for the event to become signaled, for the specified number of |
| 41 | // |milliseconds|. To wait indefinetly, pass kForever. |
| 42 | bool Wait(int milliseconds); |
| 43 |
| 44 | private: |
| 45 | #if defined(WEBRTC_WIN) |
| 46 | HANDLE event_handle_; |
| 47 | #elif defined(WEBRTC_POSIX) |
| 48 | pthread_mutex_t event_mutex_; |
| 49 | pthread_cond_t event_cond_; |
| 50 | const bool is_manual_reset_; |
| 51 | bool event_status_; |
| 52 | #endif |
| 53 | }; |
| 54 |
| 55 | // This class is provided for compatibility with Chromium. |
| 56 | // The rtc::Event implementation is overriden inside of Chromium for the |
| 57 | // purposes of detecting when threads are blocked that shouldn't be as well as |
| 58 | // to use the more accurate event implementation that's there than is provided |
| 59 | // by default on some platforms (e.g. Windows). |
| 60 | // When building with standalone WebRTC, this class is a noop. |
| 61 | // For further information, please see the ScopedAllowBaseSyncPrimitives class |
| 62 | // in Chromium. |
| 63 | class ScopedAllowBaseSyncPrimitives |
| 64 | { |
| 65 | public: |
| 66 | ScopedAllowBaseSyncPrimitives() {} |
| 67 | ~ScopedAllowBaseSyncPrimitives() {} |
| 68 | }; |
| 69 |
| 70 | } // namespace rtc |
| 71 |
| 72 | #endif // RTC_BASE_EVENT_H_ |
| 73 |