• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2010 Vicente J. Botet Escriba
3  * Copyright 2015 Andrey Semashev
4  *
5  * Distributed under the Boost Software License, Version 1.0.
6  * See http://www.boost.org/LICENSE_1_0.txt
7  */
8 
9 #ifndef BOOST_WINAPI_CONDITION_VARIABLE_HPP_INCLUDED_
10 #define BOOST_WINAPI_CONDITION_VARIABLE_HPP_INCLUDED_
11 
12 #include <boost/winapi/config.hpp>
13 
14 #ifdef BOOST_HAS_PRAGMA_ONCE
15 #pragma once
16 #endif
17 
18 #if BOOST_USE_WINAPI_VERSION >= BOOST_WINAPI_VERSION_WIN6
19 
20 #include <boost/winapi/basic_types.hpp>
21 #include <boost/winapi/detail/header.hpp>
22 
23 #if !defined( BOOST_USE_WINDOWS_H )
24 extern "C" {
25 struct _RTL_CONDITION_VARIABLE;
26 struct _RTL_CRITICAL_SECTION;
27 struct _RTL_SRWLOCK;
28 
29 BOOST_WINAPI_IMPORT boost::winapi::VOID_ BOOST_WINAPI_WINAPI_CC
30 InitializeConditionVariable(::_RTL_CONDITION_VARIABLE* ConditionVariable);
31 
32 BOOST_WINAPI_IMPORT boost::winapi::VOID_ BOOST_WINAPI_WINAPI_CC
33 WakeConditionVariable(::_RTL_CONDITION_VARIABLE* ConditionVariable);
34 
35 BOOST_WINAPI_IMPORT boost::winapi::VOID_ BOOST_WINAPI_WINAPI_CC
36 WakeAllConditionVariable(::_RTL_CONDITION_VARIABLE* ConditionVariable);
37 
38 BOOST_WINAPI_IMPORT boost::winapi::BOOL_ BOOST_WINAPI_WINAPI_CC
39 SleepConditionVariableCS(
40     ::_RTL_CONDITION_VARIABLE* ConditionVariable,
41     ::_RTL_CRITICAL_SECTION* CriticalSection,
42     boost::winapi::DWORD_ dwMilliseconds);
43 
44 BOOST_WINAPI_IMPORT boost::winapi::BOOL_ BOOST_WINAPI_WINAPI_CC
45 SleepConditionVariableSRW(
46     ::_RTL_CONDITION_VARIABLE* ConditionVariable,
47     ::_RTL_SRWLOCK* SRWLock,
48     boost::winapi::DWORD_ dwMilliseconds,
49     boost::winapi::ULONG_ Flags);
50 }
51 #endif
52 
53 namespace boost {
54 namespace winapi {
55 
56 typedef struct BOOST_MAY_ALIAS _RTL_CONDITION_VARIABLE {
57     PVOID_ Ptr;
58 } CONDITION_VARIABLE_, *PCONDITION_VARIABLE_;
59 
60 #if defined( BOOST_USE_WINDOWS_H )
61 #define BOOST_WINAPI_CONDITION_VARIABLE_INIT CONDITION_VARIABLE_INIT
62 #else
63 #define BOOST_WINAPI_CONDITION_VARIABLE_INIT {0}
64 #endif
65 
66 struct _RTL_CRITICAL_SECTION;
67 struct _RTL_SRWLOCK;
68 
InitializeConditionVariable(PCONDITION_VARIABLE_ ConditionVariable)69 BOOST_FORCEINLINE VOID_ InitializeConditionVariable(PCONDITION_VARIABLE_ ConditionVariable)
70 {
71     ::InitializeConditionVariable(reinterpret_cast< ::_RTL_CONDITION_VARIABLE* >(ConditionVariable));
72 }
73 
WakeConditionVariable(PCONDITION_VARIABLE_ ConditionVariable)74 BOOST_FORCEINLINE VOID_ WakeConditionVariable(PCONDITION_VARIABLE_ ConditionVariable)
75 {
76     ::WakeConditionVariable(reinterpret_cast< ::_RTL_CONDITION_VARIABLE* >(ConditionVariable));
77 }
78 
WakeAllConditionVariable(PCONDITION_VARIABLE_ ConditionVariable)79 BOOST_FORCEINLINE VOID_ WakeAllConditionVariable(PCONDITION_VARIABLE_ ConditionVariable)
80 {
81     ::WakeAllConditionVariable(reinterpret_cast< ::_RTL_CONDITION_VARIABLE* >(ConditionVariable));
82 }
83 
SleepConditionVariableCS(PCONDITION_VARIABLE_ ConditionVariable,_RTL_CRITICAL_SECTION * CriticalSection,DWORD_ dwMilliseconds)84 BOOST_FORCEINLINE BOOL_ SleepConditionVariableCS(
85     PCONDITION_VARIABLE_ ConditionVariable,
86     _RTL_CRITICAL_SECTION* CriticalSection,
87     DWORD_ dwMilliseconds)
88 {
89     return ::SleepConditionVariableCS(
90         reinterpret_cast< ::_RTL_CONDITION_VARIABLE* >(ConditionVariable),
91         reinterpret_cast< ::_RTL_CRITICAL_SECTION* >(CriticalSection),
92         dwMilliseconds);
93 }
94 
SleepConditionVariableSRW(PCONDITION_VARIABLE_ ConditionVariable,_RTL_SRWLOCK * SRWLock,DWORD_ dwMilliseconds,ULONG_ Flags)95 BOOST_FORCEINLINE BOOL_ SleepConditionVariableSRW(
96     PCONDITION_VARIABLE_ ConditionVariable,
97     _RTL_SRWLOCK* SRWLock,
98     DWORD_ dwMilliseconds,
99     ULONG_ Flags)
100 {
101     return ::SleepConditionVariableSRW(
102         reinterpret_cast< ::_RTL_CONDITION_VARIABLE* >(ConditionVariable),
103         reinterpret_cast< ::_RTL_SRWLOCK* >(SRWLock),
104         dwMilliseconds,
105         Flags);
106 }
107 
108 #if defined( BOOST_USE_WINDOWS_H )
109 BOOST_CONSTEXPR_OR_CONST ULONG_ CONDITION_VARIABLE_LOCKMODE_SHARED_ = CONDITION_VARIABLE_LOCKMODE_SHARED;
110 #else // defined( BOOST_USE_WINDOWS_H )
111 BOOST_CONSTEXPR_OR_CONST ULONG_ CONDITION_VARIABLE_LOCKMODE_SHARED_ = 0x00000001;
112 #endif // defined( BOOST_USE_WINDOWS_H )
113 
114 BOOST_CONSTEXPR_OR_CONST ULONG_ condition_variable_lockmode_shared = CONDITION_VARIABLE_LOCKMODE_SHARED_;
115 
116 }
117 }
118 
119 #include <boost/winapi/detail/footer.hpp>
120 
121 #endif // BOOST_USE_WINAPI_VERSION >= BOOST_WINAPI_VERSION_WIN6
122 
123 #endif // BOOST_WINAPI_CONDITION_VARIABLE_HPP_INCLUDED_
124