blob: bdf14a8cc1f984b36ae2acedf5be1b494e8d8710 [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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020014#include "rtc_base/constructormagic.h"
Henrik Kjellanderec78f1c2017-06-29 07:52:50 +020015#if defined(WEBRTC_WIN)
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020016#include "rtc_base/win32.h" // NOLINT: consider this a system header.
Henrik Kjellanderec78f1c2017-06-29 07:52:50 +020017#elif defined(WEBRTC_POSIX)
18#include <pthread.h>
19#else
20#error "Must define either WEBRTC_WIN or WEBRTC_POSIX."
21#endif
henrike@webrtc.orgf0488722014-05-13 18:00:26 +000022
Henrik Kjellanderec78f1c2017-06-29 07:52:50 +020023namespace rtc {
henrike@webrtc.orgf0488722014-05-13 18:00:26 +000024
Henrik Kjellanderec78f1c2017-06-29 07:52:50 +020025class Event {
26 public:
27 static const int kForever = -1;
28
29 Event(bool manual_reset, bool initially_signaled);
30 ~Event();
31
32 void Set();
33 void Reset();
34
35 // Wait for the event to become signaled, for the specified number of
36 // |milliseconds|. To wait indefinetly, pass kForever.
37 bool Wait(int milliseconds);
38
39 private:
40#if defined(WEBRTC_WIN)
41 HANDLE event_handle_;
42#elif defined(WEBRTC_POSIX)
43 pthread_mutex_t event_mutex_;
44 pthread_cond_t event_cond_;
45 const bool is_manual_reset_;
46 bool event_status_;
47#endif
48
49 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(Event);
50};
51
52} // namespace rtc
53
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020054#endif // RTC_BASE_EVENT_H_