blob: ea686174f2bfbff3b96f6d4d39f99ef2bd342b3d [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
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
11#ifndef WEBRTC_SYSTEM_WRAPPERS_INTERFACE_EVENT_WRAPPER_H_
12#define WEBRTC_SYSTEM_WRAPPERS_INTERFACE_EVENT_WRAPPER_H_
13
14namespace webrtc {
phoglund@webrtc.org5bbe0692012-12-10 10:44:37 +000015enum EventTypeWrapper {
16 kEventSignaled = 1,
17 kEventError = 2,
18 kEventTimeout = 3
niklase@google.com470e71d2011-07-07 08:21:25 +000019};
20
Minyuecf3c83e2015-04-01 16:31:38 +020021#define WEBRTC_EVENT_10_SEC 10000
niklase@google.com470e71d2011-07-07 08:21:25 +000022#define WEBRTC_EVENT_INFINITE 0xffffffff
23
phoglund@webrtc.org5bbe0692012-12-10 10:44:37 +000024class EventWrapper {
25 public:
26 // Factory method. Constructor disabled.
27 static EventWrapper* Create();
28 virtual ~EventWrapper() {}
niklase@google.com470e71d2011-07-07 08:21:25 +000029
phoglund@webrtc.org5bbe0692012-12-10 10:44:37 +000030 // Releases threads who are calling Wait() and has started waiting. Please
31 // note that a thread calling Wait() will not start waiting immediately.
32 // assumptions to the contrary is a very common source of issues in
33 // multithreaded programming.
34 // Set is sticky in the sense that it will release at least one thread
35 // either immediately or some time in the future.
36 virtual bool Set() = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000037
phoglund@webrtc.org5bbe0692012-12-10 10:44:37 +000038 // Puts the calling thread into a wait state. The thread may be released
39 // by a Set() call depending on if other threads are waiting and if so on
40 // timing. The thread that was released will call Reset() before leaving
41 // preventing more threads from being released. If multiple threads
42 // are waiting for the same Set(), only one (random) thread is guaranteed to
43 // be released. It is possible that multiple (random) threads are released
44 // Depending on timing.
45 virtual EventTypeWrapper Wait(unsigned long max_time) = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000046
phoglund@webrtc.org5bbe0692012-12-10 10:44:37 +000047 // Starts a timer that will call a non-sticky version of Set() either once
48 // or periodically. If the timer is periodic it ensures that there is no
49 // drift over time relative to the system clock.
50 virtual bool StartTimer(bool periodic, unsigned long time) = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000051
phoglund@webrtc.org5bbe0692012-12-10 10:44:37 +000052 virtual bool StopTimer() = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000053
niklase@google.com470e71d2011-07-07 08:21:25 +000054};
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +000055} // namespace webrtc
niklase@google.com470e71d2011-07-07 08:21:25 +000056
phoglund@webrtc.org5bbe0692012-12-10 10:44:37 +000057#endif // WEBRTC_SYSTEM_WRAPPERS_INTERFACE_EVENT_WRAPPER_H_