niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2011 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 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #ifndef SYSTEM_WRAPPERS_INCLUDE_EVENT_WRAPPER_H_ |
| 12 | #define SYSTEM_WRAPPERS_INCLUDE_EVENT_WRAPPER_H_ |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 13 | |
| 14 | namespace webrtc { |
Niels Möller | 2c16cc6 | 2018-10-29 09:47:51 +0100 | [diff] [blame] | 15 | enum EventTypeWrapper { kEventSignaled = 1, kEventTimeout = 2 }; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 16 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 17 | #define WEBRTC_EVENT_INFINITE 0xffffffff |
| 18 | |
phoglund@webrtc.org | 5bbe069 | 2012-12-10 10:44:37 +0000 | [diff] [blame] | 19 | class EventWrapper { |
| 20 | public: |
| 21 | // Factory method. Constructor disabled. |
| 22 | static EventWrapper* Create(); |
Peter Boström | 64c0366 | 2015-04-08 11:24:19 +0200 | [diff] [blame] | 23 | |
phoglund@webrtc.org | 5bbe069 | 2012-12-10 10:44:37 +0000 | [diff] [blame] | 24 | virtual ~EventWrapper() {} |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 25 | |
phoglund@webrtc.org | 5bbe069 | 2012-12-10 10:44:37 +0000 | [diff] [blame] | 26 | // Releases threads who are calling Wait() and has started waiting. Please |
| 27 | // note that a thread calling Wait() will not start waiting immediately. |
| 28 | // assumptions to the contrary is a very common source of issues in |
| 29 | // multithreaded programming. |
| 30 | // Set is sticky in the sense that it will release at least one thread |
| 31 | // either immediately or some time in the future. |
| 32 | virtual bool Set() = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 33 | |
phoglund@webrtc.org | 5bbe069 | 2012-12-10 10:44:37 +0000 | [diff] [blame] | 34 | // Puts the calling thread into a wait state. The thread may be released |
| 35 | // by a Set() call depending on if other threads are waiting and if so on |
Wan-Teh Chang | 5a8bad6 | 2015-05-29 09:41:38 -0700 | [diff] [blame] | 36 | // timing. The thread that was released will reset the event before leaving |
phoglund@webrtc.org | 5bbe069 | 2012-12-10 10:44:37 +0000 | [diff] [blame] | 37 | // preventing more threads from being released. If multiple threads |
| 38 | // are waiting for the same Set(), only one (random) thread is guaranteed to |
| 39 | // be released. It is possible that multiple (random) threads are released |
| 40 | // Depending on timing. |
Wan-Teh Chang | 76cda01 | 2015-06-01 17:33:40 -0700 | [diff] [blame] | 41 | // |
| 42 | // |max_time| is the maximum time to wait in milliseconds or |
| 43 | // WEBRTC_EVENT_INFINITE to wait infinitely. |
phoglund@webrtc.org | 5bbe069 | 2012-12-10 10:44:37 +0000 | [diff] [blame] | 44 | virtual EventTypeWrapper Wait(unsigned long max_time) = 0; |
Peter Boström | 64c0366 | 2015-04-08 11:24:19 +0200 | [diff] [blame] | 45 | }; |
| 46 | |
pbos@webrtc.org | d900e8b | 2013-07-03 15:12:26 +0000 | [diff] [blame] | 47 | } // namespace webrtc |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 48 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 49 | #endif // SYSTEM_WRAPPERS_INCLUDE_EVENT_WRAPPER_H_ |