henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2004 The WebRTC Project Authors. All rights reserved. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license |
| 5 | * that can be found in the LICENSE file in the root of the source |
| 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 WEBRTC_BASE_EVENT_H__ |
| 12 | #define WEBRTC_BASE_EVENT_H__ |
| 13 | |
| 14 | #if defined(WEBRTC_WIN) |
| 15 | #include "webrtc/base/win32.h" // NOLINT: consider this a system header. |
| 16 | #elif defined(WEBRTC_POSIX) |
| 17 | #include <pthread.h> |
| 18 | #else |
| 19 | #error "Must define either WEBRTC_WIN or WEBRTC_POSIX." |
| 20 | #endif |
| 21 | |
| 22 | #include "webrtc/base/basictypes.h" |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 23 | |
| 24 | namespace rtc { |
| 25 | |
| 26 | class Event { |
| 27 | public: |
andresp@webrtc.org | 53d9012 | 2015-02-09 14:19:09 +0000 | [diff] [blame] | 28 | static const int kForever = -1; |
| 29 | |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 30 | Event(bool manual_reset, bool initially_signaled); |
| 31 | ~Event(); |
| 32 | |
| 33 | void Set(); |
| 34 | void Reset(); |
tommi@webrtc.org | 1a072f9 | 2015-02-10 12:27:48 +0000 | [diff] [blame] | 35 | |
| 36 | // Wait for the event to become signaled, for the specified number of |
| 37 | // |milliseconds|. To wait indefinetly, pass kForever. |
| 38 | bool Wait(int milliseconds); |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 39 | |
| 40 | private: |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 41 | #if defined(WEBRTC_WIN) |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 42 | HANDLE event_handle_; |
| 43 | #elif defined(WEBRTC_POSIX) |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 44 | pthread_mutex_t event_mutex_; |
| 45 | pthread_cond_t event_cond_; |
tommi@webrtc.org | 4c0fd96 | 2015-02-09 10:23:27 +0000 | [diff] [blame] | 46 | const bool is_manual_reset_; |
| 47 | bool event_status_; |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 48 | #endif |
| 49 | }; |
| 50 | |
| 51 | } // namespace rtc |
| 52 | |
| 53 | #endif // WEBRTC_BASE_EVENT_H__ |