blob: 6f90ead2253fc60fea8091fd1d96bfeea74aa4e9 [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
phoglund@webrtc.orga36d75a2012-11-14 09:55:04 +000011#ifndef WEBRTC_SYSTEM_WRAPPERS_SOURCE_CONDITION_VARIABLE_WIN_H_
12#define WEBRTC_SYSTEM_WRAPPERS_SOURCE_CONDITION_VARIABLE_WIN_H_
niklase@google.com470e71d2011-07-07 08:21:25 +000013
14#include <windows.h>
15
phoglund@webrtc.orga36d75a2012-11-14 09:55:04 +000016#include "condition_variable_wrapper.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000017
phoglund@webrtc.orga36d75a2012-11-14 09:55:04 +000018namespace webrtc {
19
20#if !defined CONDITION_VARIABLE_INIT
21typedef struct RTL_CONDITION_VARIABLE_ {
22 void* Ptr;
23} RTL_CONDITION_VARIABLE, *PRTL_CONDITION_VARIABLE;
24
25typedef RTL_CONDITION_VARIABLE CONDITION_VARIABLE, *PCONDITION_VARIABLE;
niklase@google.com470e71d2011-07-07 08:21:25 +000026#endif
27
phoglund@webrtc.orga36d75a2012-11-14 09:55:04 +000028typedef void (WINAPI* PInitializeConditionVariable)(PCONDITION_VARIABLE);
29typedef BOOL (WINAPI* PSleepConditionVariableCS)(PCONDITION_VARIABLE,
niklase@google.com470e71d2011-07-07 08:21:25 +000030 PCRITICAL_SECTION, DWORD);
phoglund@webrtc.orga36d75a2012-11-14 09:55:04 +000031typedef void (WINAPI* PWakeConditionVariable)(PCONDITION_VARIABLE);
32typedef void (WINAPI* PWakeAllConditionVariable)(PCONDITION_VARIABLE);
niklase@google.com470e71d2011-07-07 08:21:25 +000033
phoglund@webrtc.orga36d75a2012-11-14 09:55:04 +000034class ConditionVariableWindows : public ConditionVariableWrapper {
35 public:
36 ConditionVariableWindows();
37 ~ConditionVariableWindows();
niklase@google.com470e71d2011-07-07 08:21:25 +000038
phoglund@webrtc.orga36d75a2012-11-14 09:55:04 +000039 void SleepCS(CriticalSectionWrapper& crit_sect);
40 bool SleepCS(CriticalSectionWrapper& crit_sect, unsigned long max_time_inMS);
41 void Wake();
42 void WakeAll();
niklase@google.com470e71d2011-07-07 08:21:25 +000043
phoglund@webrtc.orga36d75a2012-11-14 09:55:04 +000044 private:
45 enum EventWakeUpType {
46 WAKEALL_0 = 0,
47 WAKEALL_1 = 1,
48 WAKE = 2,
49 EVENT_COUNT = 3
50 };
niklase@google.com470e71d2011-07-07 08:21:25 +000051
phoglund@webrtc.orga36d75a2012-11-14 09:55:04 +000052 private:
53 // Native support for Windows Vista+
54 static bool win_support_condition_variables_primitive_;
55 CONDITION_VARIABLE condition_variable_;
niklase@google.com470e71d2011-07-07 08:21:25 +000056
phoglund@webrtc.orga36d75a2012-11-14 09:55:04 +000057 unsigned int num_waiters_[2];
58 EventWakeUpType eventID_;
59 CRITICAL_SECTION num_waiters_crit_sect_;
60 HANDLE events_[EVENT_COUNT];
niklase@google.com470e71d2011-07-07 08:21:25 +000061};
phoglund@webrtc.orga36d75a2012-11-14 09:55:04 +000062
niklase@google.com470e71d2011-07-07 08:21:25 +000063} // namespace webrtc
64
phoglund@webrtc.orga36d75a2012-11-14 09:55:04 +000065#endif // WEBRTC_SYSTEM_WRAPPERS_SOURCE_CONDITION_VARIABLE_WIN_H_