blob: d4b58724f0e3953b5cb213e0d3d9ce060523795b [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
11#ifndef WEBRTC_BASE_EVENT_H__
12#define WEBRTC_BASE_EVENT_H__
13
deadbeef162cb532017-02-23 17:10:07 -080014#include "webrtc/base/constructormagic.h"
henrike@webrtc.orgf0488722014-05-13 18:00:26 +000015#if defined(WEBRTC_WIN)
16#include "webrtc/base/win32.h" // NOLINT: consider this a system header.
17#elif defined(WEBRTC_POSIX)
18#include <pthread.h>
19#else
20#error "Must define either WEBRTC_WIN or WEBRTC_POSIX."
21#endif
22
henrike@webrtc.orgf0488722014-05-13 18:00:26 +000023namespace rtc {
24
25class Event {
26 public:
andresp@webrtc.org53d90122015-02-09 14:19:09 +000027 static const int kForever = -1;
28
henrike@webrtc.orgf0488722014-05-13 18:00:26 +000029 Event(bool manual_reset, bool initially_signaled);
30 ~Event();
31
32 void Set();
33 void Reset();
tommi@webrtc.org1a072f92015-02-10 12:27:48 +000034
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);
henrike@webrtc.orgf0488722014-05-13 18:00:26 +000038
39 private:
henrike@webrtc.orgf0488722014-05-13 18:00:26 +000040#if defined(WEBRTC_WIN)
henrike@webrtc.orgf0488722014-05-13 18:00:26 +000041 HANDLE event_handle_;
42#elif defined(WEBRTC_POSIX)
henrike@webrtc.orgf0488722014-05-13 18:00:26 +000043 pthread_mutex_t event_mutex_;
44 pthread_cond_t event_cond_;
tommi@webrtc.org4c0fd962015-02-09 10:23:27 +000045 const bool is_manual_reset_;
46 bool event_status_;
henrike@webrtc.orgf0488722014-05-13 18:00:26 +000047#endif
deadbeef162cb532017-02-23 17:10:07 -080048
49 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(Event);
henrike@webrtc.orgf0488722014-05-13 18:00:26 +000050};
51
52} // namespace rtc
53
54#endif // WEBRTC_BASE_EVENT_H__