blob: c5e56612822d4ee22d386efad2c585d0ba6cec25 [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
Niels Möllerd3da6b02020-03-05 15:31:10 +010011#ifndef MODULES_VIDEO_CODING_EVENT_WRAPPER_H_
12#define MODULES_VIDEO_CODING_EVENT_WRAPPER_H_
niklase@google.com470e71d2011-07-07 08:21:25 +000013
14namespace webrtc {
Niels Möller2c16cc62018-10-29 09:47:51 +010015enum EventTypeWrapper { kEventSignaled = 1, kEventTimeout = 2 };
niklase@google.com470e71d2011-07-07 08:21:25 +000016
phoglund@webrtc.org5bbe0692012-12-10 10:44:37 +000017class EventWrapper {
18 public:
19 // Factory method. Constructor disabled.
20 static EventWrapper* Create();
Peter Boström64c03662015-04-08 11:24:19 +020021
phoglund@webrtc.org5bbe0692012-12-10 10:44:37 +000022 virtual ~EventWrapper() {}
niklase@google.com470e71d2011-07-07 08:21:25 +000023
phoglund@webrtc.org5bbe0692012-12-10 10:44:37 +000024 // Releases threads who are calling Wait() and has started waiting. Please
25 // note that a thread calling Wait() will not start waiting immediately.
26 // assumptions to the contrary is a very common source of issues in
27 // multithreaded programming.
28 // Set is sticky in the sense that it will release at least one thread
29 // either immediately or some time in the future.
30 virtual bool Set() = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000031
phoglund@webrtc.org5bbe0692012-12-10 10:44:37 +000032 // Puts the calling thread into a wait state. The thread may be released
33 // by a Set() call depending on if other threads are waiting and if so on
Wan-Teh Chang5a8bad62015-05-29 09:41:38 -070034 // timing. The thread that was released will reset the event before leaving
phoglund@webrtc.org5bbe0692012-12-10 10:44:37 +000035 // preventing more threads from being released. If multiple threads
36 // are waiting for the same Set(), only one (random) thread is guaranteed to
37 // be released. It is possible that multiple (random) threads are released
38 // Depending on timing.
Wan-Teh Chang76cda012015-06-01 17:33:40 -070039 //
Artem Titovdcd7fc72021-08-09 13:02:57 +020040 // `max_time_ms` is the maximum time to wait in milliseconds.
Markus Handell2cfc1af2022-08-19 08:16:48 +000041 // TODO(bugs.webrtc.org/14366): Migrate to TimeDelta.
Niels Möllerd3da6b02020-03-05 15:31:10 +010042 virtual EventTypeWrapper Wait(int max_time_ms) = 0;
Peter Boström64c03662015-04-08 11:24:19 +020043};
44
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +000045} // namespace webrtc
niklase@google.com470e71d2011-07-07 08:21:25 +000046
Niels Möllerd3da6b02020-03-05 15:31:10 +010047#endif // MODULES_VIDEO_CODING_EVENT_WRAPPER_H_