blob: 3f5f8b317c65fa075ae83ae1412a384477804b1e [file] [log] [blame]
henrike@webrtc.orgf0488722014-05-13 18:00:26 +00001/*
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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#ifndef RTC_BASE_EVENT_H_
12#define RTC_BASE_EVENT_H_
henrike@webrtc.orgf0488722014-05-13 18:00:26 +000013
Henrik Kjellanderec78f1c2017-06-29 07:52:50 +020014#if defined(WEBRTC_WIN)
Patrik Höglunda8005cf2017-12-13 16:05:42 +010015#include <windows.h>
Henrik Kjellanderec78f1c2017-06-29 07:52:50 +020016#elif defined(WEBRTC_POSIX)
17#include <pthread.h>
18#else
19#error "Must define either WEBRTC_WIN or WEBRTC_POSIX."
20#endif
henrike@webrtc.orgf0488722014-05-13 18:00:26 +000021
Henrik Kjellanderec78f1c2017-06-29 07:52:50 +020022namespace rtc {
henrike@webrtc.orgf0488722014-05-13 18:00:26 +000023
Henrik Kjellanderec78f1c2017-06-29 07:52:50 +020024class Event {
25 public:
26 static const int kForever = -1;
27
Niels Möllerc572ff32018-11-07 08:43:50 +010028 Event();
Henrik Kjellanderec78f1c2017-06-29 07:52:50 +020029 Event(bool manual_reset, bool initially_signaled);
Niels Möllerc572ff32018-11-07 08:43:50 +010030 Event(const Event&) = delete;
31 Event& operator=(const Event&) = delete;
Henrik Kjellanderec78f1c2017-06-29 07:52:50 +020032 ~Event();
33
34 void Set();
35 void Reset();
36
37 // Wait for the event to become signaled, for the specified number of
38 // |milliseconds|. To wait indefinetly, pass kForever.
39 bool Wait(int milliseconds);
40
41 private:
42#if defined(WEBRTC_WIN)
43 HANDLE event_handle_;
44#elif defined(WEBRTC_POSIX)
45 pthread_mutex_t event_mutex_;
46 pthread_cond_t event_cond_;
47 const bool is_manual_reset_;
48 bool event_status_;
49#endif
Henrik Kjellanderec78f1c2017-06-29 07:52:50 +020050};
51
François Doray8ea977d2019-03-22 13:01:54 -040052// These classes are provided for compatibility with Chromium.
Tommi39d93da2018-01-17 12:31:13 +010053// The rtc::Event implementation is overriden inside of Chromium for the
54// purposes of detecting when threads are blocked that shouldn't be as well as
55// to use the more accurate event implementation that's there than is provided
56// by default on some platforms (e.g. Windows).
57// When building with standalone WebRTC, this class is a noop.
François Doray8ea977d2019-03-22 13:01:54 -040058// For further information, please see the
59// ScopedAllowBaseSyncPrimitives(ForTesting) classes in Chromium.
Tommi39d93da2018-01-17 12:31:13 +010060class ScopedAllowBaseSyncPrimitives {
61 public:
62 ScopedAllowBaseSyncPrimitives() {}
63 ~ScopedAllowBaseSyncPrimitives() {}
64};
65
François Doray8ea977d2019-03-22 13:01:54 -040066class ScopedAllowBaseSyncPrimitivesForTesting {
67 public:
68 ScopedAllowBaseSyncPrimitivesForTesting() {}
69 ~ScopedAllowBaseSyncPrimitivesForTesting() {}
70};
71
Henrik Kjellanderec78f1c2017-06-29 07:52:50 +020072} // namespace rtc
73
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020074#endif // RTC_BASE_EVENT_H_