niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1 | /* |
| 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.org | a36d75a | 2012-11-14 09:55:04 +0000 | [diff] [blame] | 11 | #ifndef WEBRTC_SYSTEM_WRAPPERS_SOURCE_CONDITION_VARIABLE_WIN_H_ |
| 12 | #define WEBRTC_SYSTEM_WRAPPERS_SOURCE_CONDITION_VARIABLE_WIN_H_ |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 13 | |
| 14 | #include <windows.h> |
| 15 | |
phoglund@webrtc.org | a36d75a | 2012-11-14 09:55:04 +0000 | [diff] [blame] | 16 | #include "condition_variable_wrapper.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 17 | |
phoglund@webrtc.org | a36d75a | 2012-11-14 09:55:04 +0000 | [diff] [blame] | 18 | namespace webrtc { |
| 19 | |
| 20 | #if !defined CONDITION_VARIABLE_INIT |
| 21 | typedef struct RTL_CONDITION_VARIABLE_ { |
| 22 | void* Ptr; |
| 23 | } RTL_CONDITION_VARIABLE, *PRTL_CONDITION_VARIABLE; |
| 24 | |
| 25 | typedef RTL_CONDITION_VARIABLE CONDITION_VARIABLE, *PCONDITION_VARIABLE; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 26 | #endif |
| 27 | |
phoglund@webrtc.org | a36d75a | 2012-11-14 09:55:04 +0000 | [diff] [blame] | 28 | typedef void (WINAPI* PInitializeConditionVariable)(PCONDITION_VARIABLE); |
| 29 | typedef BOOL (WINAPI* PSleepConditionVariableCS)(PCONDITION_VARIABLE, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 30 | PCRITICAL_SECTION, DWORD); |
phoglund@webrtc.org | a36d75a | 2012-11-14 09:55:04 +0000 | [diff] [blame] | 31 | typedef void (WINAPI* PWakeConditionVariable)(PCONDITION_VARIABLE); |
| 32 | typedef void (WINAPI* PWakeAllConditionVariable)(PCONDITION_VARIABLE); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 33 | |
phoglund@webrtc.org | a36d75a | 2012-11-14 09:55:04 +0000 | [diff] [blame] | 34 | class ConditionVariableWindows : public ConditionVariableWrapper { |
| 35 | public: |
| 36 | ConditionVariableWindows(); |
| 37 | ~ConditionVariableWindows(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 38 | |
phoglund@webrtc.org | a36d75a | 2012-11-14 09:55:04 +0000 | [diff] [blame] | 39 | void SleepCS(CriticalSectionWrapper& crit_sect); |
| 40 | bool SleepCS(CriticalSectionWrapper& crit_sect, unsigned long max_time_inMS); |
| 41 | void Wake(); |
| 42 | void WakeAll(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 43 | |
phoglund@webrtc.org | a36d75a | 2012-11-14 09:55:04 +0000 | [diff] [blame] | 44 | private: |
| 45 | enum EventWakeUpType { |
| 46 | WAKEALL_0 = 0, |
| 47 | WAKEALL_1 = 1, |
| 48 | WAKE = 2, |
| 49 | EVENT_COUNT = 3 |
| 50 | }; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 51 | |
phoglund@webrtc.org | a36d75a | 2012-11-14 09:55:04 +0000 | [diff] [blame] | 52 | private: |
| 53 | // Native support for Windows Vista+ |
| 54 | static bool win_support_condition_variables_primitive_; |
| 55 | CONDITION_VARIABLE condition_variable_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 56 | |
phoglund@webrtc.org | a36d75a | 2012-11-14 09:55:04 +0000 | [diff] [blame] | 57 | unsigned int num_waiters_[2]; |
| 58 | EventWakeUpType eventID_; |
| 59 | CRITICAL_SECTION num_waiters_crit_sect_; |
| 60 | HANDLE events_[EVENT_COUNT]; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 61 | }; |
phoglund@webrtc.org | a36d75a | 2012-11-14 09:55:04 +0000 | [diff] [blame] | 62 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 63 | } // namespace webrtc |
| 64 | |
phoglund@webrtc.org | a36d75a | 2012-11-14 09:55:04 +0000 | [diff] [blame] | 65 | #endif // WEBRTC_SYSTEM_WRAPPERS_SOURCE_CONDITION_VARIABLE_WIN_H_ |