blob: 523715194a2abd3a393d184de6f5592d9debf562 [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
14#if defined(WEBRTC_WIN)
15#include "webrtc/base/win32.h" // NOLINT: consider this a system header.
16#elif defined(WEBRTC_POSIX)
17#include <pthread.h>
18#else
19#error "Must define either WEBRTC_WIN or WEBRTC_POSIX."
20#endif
21
22#include "webrtc/base/basictypes.h"
henrike@webrtc.orgf0488722014-05-13 18:00:26 +000023
24namespace rtc {
25
26class Event {
27 public:
andresp@webrtc.org53d90122015-02-09 14:19:09 +000028 static const int kForever = -1;
29
henrike@webrtc.orgf0488722014-05-13 18:00:26 +000030 Event(bool manual_reset, bool initially_signaled);
31 ~Event();
32
33 void Set();
34 void Reset();
tommi@webrtc.org1a072f92015-02-10 12:27:48 +000035
36 // Wait for the event to become signaled, for the specified number of
37 // |milliseconds|. To wait indefinetly, pass kForever.
38 bool Wait(int milliseconds);
henrike@webrtc.orgf0488722014-05-13 18:00:26 +000039
40 private:
henrike@webrtc.orgf0488722014-05-13 18:00:26 +000041#if defined(WEBRTC_WIN)
henrike@webrtc.orgf0488722014-05-13 18:00:26 +000042 HANDLE event_handle_;
43#elif defined(WEBRTC_POSIX)
henrike@webrtc.orgf0488722014-05-13 18:00:26 +000044 pthread_mutex_t event_mutex_;
45 pthread_cond_t event_cond_;
tommi@webrtc.org4c0fd962015-02-09 10:23:27 +000046 const bool is_manual_reset_;
47 bool event_status_;
henrike@webrtc.orgf0488722014-05-13 18:00:26 +000048#endif
49};
50
51} // namespace rtc
52
53#endif // WEBRTC_BASE_EVENT_H__