]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | // semaphore.hpp --------------------------------------------------------------// |
2 | ||
3 | // Copyright 2010 Vicente J. Botet Escriba | |
4 | // Copyright 2015 Andrey Semashev | |
5 | ||
6 | // Distributed under the Boost Software License, Version 1.0. | |
7 | // See http://www.boost.org/LICENSE_1_0.txt | |
8 | ||
9 | ||
10 | #ifndef BOOST_DETAIL_WINAPI_SEMAPHORE_HPP | |
11 | #define BOOST_DETAIL_WINAPI_SEMAPHORE_HPP | |
12 | ||
13 | #include <boost/detail/winapi/basic_types.hpp> | |
14 | #include <boost/predef/platform.h> | |
15 | ||
16 | #ifdef BOOST_HAS_PRAGMA_ONCE | |
17 | #pragma once | |
18 | #endif | |
19 | ||
20 | #if !defined( BOOST_USE_WINDOWS_H ) | |
21 | extern "C" { | |
22 | #if !defined( BOOST_NO_ANSI_APIS ) | |
23 | #if !defined( BOOST_PLAT_WINDOWS_RUNTIME_AVALIABLE ) | |
24 | BOOST_SYMBOL_IMPORT boost::detail::winapi::HANDLE_ WINAPI | |
25 | CreateSemaphoreA( | |
26 | ::_SECURITY_ATTRIBUTES* lpSemaphoreAttributes, | |
27 | boost::detail::winapi::LONG_ lInitialCount, | |
28 | boost::detail::winapi::LONG_ lMaximumCount, | |
29 | boost::detail::winapi::LPCSTR_ lpName); | |
30 | #endif | |
31 | ||
32 | #if BOOST_USE_WINAPI_VERSION >= BOOST_WINAPI_VERSION_WIN6 | |
33 | BOOST_SYMBOL_IMPORT boost::detail::winapi::HANDLE_ WINAPI | |
34 | CreateSemaphoreExA( | |
35 | ::_SECURITY_ATTRIBUTES* lpSemaphoreAttributes, | |
36 | boost::detail::winapi::LONG_ lInitialCount, | |
37 | boost::detail::winapi::LONG_ lMaximumCount, | |
38 | boost::detail::winapi::LPCSTR_ lpName, | |
39 | boost::detail::winapi::DWORD_ dwFlags, | |
40 | boost::detail::winapi::DWORD_ dwDesiredAccess); | |
41 | #endif | |
42 | ||
43 | BOOST_SYMBOL_IMPORT boost::detail::winapi::HANDLE_ WINAPI | |
44 | OpenSemaphoreA( | |
45 | boost::detail::winapi::DWORD_ dwDesiredAccess, | |
46 | boost::detail::winapi::BOOL_ bInheritHandle, | |
47 | boost::detail::winapi::LPCSTR_ lpName); | |
48 | #endif | |
49 | ||
50 | BOOST_SYMBOL_IMPORT boost::detail::winapi::HANDLE_ WINAPI | |
51 | CreateSemaphoreW( | |
52 | ::_SECURITY_ATTRIBUTES* lpSemaphoreAttributes, | |
53 | boost::detail::winapi::LONG_ lInitialCount, | |
54 | boost::detail::winapi::LONG_ lMaximumCount, | |
55 | boost::detail::winapi::LPCWSTR_ lpName); | |
56 | ||
57 | #if BOOST_USE_WINAPI_VERSION >= BOOST_WINAPI_VERSION_WIN6 | |
58 | BOOST_SYMBOL_IMPORT boost::detail::winapi::HANDLE_ WINAPI | |
59 | CreateSemaphoreExW( | |
60 | ::_SECURITY_ATTRIBUTES* lpSemaphoreAttributes, | |
61 | boost::detail::winapi::LONG_ lInitialCount, | |
62 | boost::detail::winapi::LONG_ lMaximumCount, | |
63 | boost::detail::winapi::LPCWSTR_ lpName, | |
64 | boost::detail::winapi::DWORD_ dwFlags, | |
65 | boost::detail::winapi::DWORD_ dwDesiredAccess); | |
66 | #endif | |
67 | ||
68 | BOOST_SYMBOL_IMPORT boost::detail::winapi::HANDLE_ WINAPI | |
69 | OpenSemaphoreW( | |
70 | boost::detail::winapi::DWORD_ dwDesiredAccess, | |
71 | boost::detail::winapi::BOOL_ bInheritHandle, | |
72 | boost::detail::winapi::LPCWSTR_ lpName); | |
73 | ||
74 | BOOST_SYMBOL_IMPORT boost::detail::winapi::BOOL_ WINAPI | |
75 | ReleaseSemaphore( | |
76 | boost::detail::winapi::HANDLE_ hSemaphore, | |
77 | boost::detail::winapi::LONG_ lReleaseCount, | |
78 | boost::detail::winapi::LPLONG_ lpPreviousCount); | |
79 | } | |
80 | #endif | |
81 | ||
82 | namespace boost { | |
83 | namespace detail { | |
84 | namespace winapi { | |
85 | ||
86 | #if !defined( BOOST_NO_ANSI_APIS ) | |
87 | using ::OpenSemaphoreA; | |
88 | #endif | |
89 | using ::OpenSemaphoreW; | |
90 | using ::ReleaseSemaphore; | |
91 | ||
92 | #if defined( BOOST_USE_WINDOWS_H ) | |
93 | ||
94 | const DWORD_ SEMAPHORE_ALL_ACCESS_ = SEMAPHORE_ALL_ACCESS; | |
95 | const DWORD_ SEMAPHORE_MODIFY_STATE_ = SEMAPHORE_MODIFY_STATE; | |
96 | ||
97 | #else // defined( BOOST_USE_WINDOWS_H ) | |
98 | ||
99 | const DWORD_ SEMAPHORE_ALL_ACCESS_ = 0x001F0003; | |
100 | const DWORD_ SEMAPHORE_MODIFY_STATE_ = 0x00000002; | |
101 | ||
102 | #endif // defined( BOOST_USE_WINDOWS_H ) | |
103 | ||
104 | // Undocumented and not present in Windows SDK. Enables NtQuerySemaphore. | |
105 | // http://undocumented.ntinternals.net/index.html?page=UserMode%2FUndocumented%20Functions%2FNT%20Objects%2FEvent%2FNtQueryEvent.html | |
106 | const DWORD_ SEMAPHORE_QUERY_STATE_ = 0x00000001; | |
107 | ||
108 | const DWORD_ semaphore_all_access = SEMAPHORE_ALL_ACCESS_; | |
109 | const DWORD_ semaphore_modify_state = SEMAPHORE_MODIFY_STATE_; | |
110 | ||
111 | ||
112 | #if !defined( BOOST_NO_ANSI_APIS ) | |
113 | BOOST_FORCEINLINE HANDLE_ CreateSemaphoreA(SECURITY_ATTRIBUTES_* lpSemaphoreAttributes, LONG_ lInitialCount, LONG_ lMaximumCount, LPCSTR_ lpName) | |
114 | { | |
115 | #if BOOST_PLAT_WINDOWS_RUNTIME && BOOST_USE_WINAPI_VERSION >= BOOST_WINAPI_VERSION_WIN6 | |
116 | return ::CreateSemaphoreExA(reinterpret_cast< ::_SECURITY_ATTRIBUTES* >(lpSemaphoreAttributes), lInitialCount, lMaximumCount, lpName, 0, semaphore_all_access); | |
117 | #else | |
118 | return ::CreateSemaphoreA(reinterpret_cast< ::_SECURITY_ATTRIBUTES* >(lpSemaphoreAttributes), lInitialCount, lMaximumCount, lpName); | |
119 | #endif | |
120 | } | |
121 | ||
122 | #if BOOST_USE_WINAPI_VERSION >= BOOST_WINAPI_VERSION_WIN6 | |
123 | BOOST_FORCEINLINE HANDLE_ CreateSemaphoreExA(SECURITY_ATTRIBUTES_* lpSemaphoreAttributes, LONG_ lInitialCount, LONG_ lMaximumCount, LPCSTR_ lpName, DWORD_ dwFlags, DWORD_ dwDesiredAccess) | |
124 | { | |
125 | return ::CreateSemaphoreExA(reinterpret_cast< ::_SECURITY_ATTRIBUTES* >(lpSemaphoreAttributes), lInitialCount, lMaximumCount, lpName, dwFlags, dwDesiredAccess); | |
126 | } | |
127 | #endif | |
128 | #endif | |
129 | ||
130 | BOOST_FORCEINLINE HANDLE_ CreateSemaphoreW(SECURITY_ATTRIBUTES_* lpSemaphoreAttributes, LONG_ lInitialCount, LONG_ lMaximumCount, LPCWSTR_ lpName) | |
131 | { | |
132 | #if BOOST_PLAT_WINDOWS_RUNTIME && BOOST_USE_WINAPI_VERSION >= BOOST_WINAPI_VERSION_WIN6 | |
133 | return ::CreateSemaphoreExW(reinterpret_cast< ::_SECURITY_ATTRIBUTES* >(lpSemaphoreAttributes), lInitialCount, lMaximumCount, lpName, 0, semaphore_all_access); | |
134 | #else | |
135 | return ::CreateSemaphoreW(reinterpret_cast< ::_SECURITY_ATTRIBUTES* >(lpSemaphoreAttributes), lInitialCount, lMaximumCount, lpName); | |
136 | #endif | |
137 | } | |
138 | ||
139 | #if BOOST_USE_WINAPI_VERSION >= BOOST_WINAPI_VERSION_WIN6 | |
140 | BOOST_FORCEINLINE HANDLE_ CreateSemaphoreExW(SECURITY_ATTRIBUTES_* lpSemaphoreAttributes, LONG_ lInitialCount, LONG_ lMaximumCount, LPCWSTR_ lpName, DWORD_ dwFlags, DWORD_ dwDesiredAccess) | |
141 | { | |
142 | return ::CreateSemaphoreExW(reinterpret_cast< ::_SECURITY_ATTRIBUTES* >(lpSemaphoreAttributes), lInitialCount, lMaximumCount, lpName, dwFlags, dwDesiredAccess); | |
143 | } | |
144 | #endif | |
145 | ||
146 | #if !defined( BOOST_NO_ANSI_APIS ) | |
147 | BOOST_FORCEINLINE HANDLE_ create_semaphore(SECURITY_ATTRIBUTES_* lpSemaphoreAttributes, LONG_ lInitialCount, LONG_ lMaximumCount, LPCSTR_ lpName) | |
148 | { | |
149 | return winapi::CreateSemaphoreA(lpSemaphoreAttributes, lInitialCount, lMaximumCount, lpName); | |
150 | } | |
151 | ||
152 | BOOST_FORCEINLINE HANDLE_ open_semaphore(DWORD_ dwDesiredAccess, BOOL_ bInheritHandle, LPCSTR_ lpName) | |
153 | { | |
154 | return ::OpenSemaphoreA(dwDesiredAccess, bInheritHandle, lpName); | |
155 | } | |
156 | #endif | |
157 | ||
158 | BOOST_FORCEINLINE HANDLE_ create_semaphore(SECURITY_ATTRIBUTES_* lpSemaphoreAttributes, LONG_ lInitialCount, LONG_ lMaximumCount, LPCWSTR_ lpName) | |
159 | { | |
160 | return winapi::CreateSemaphoreW(lpSemaphoreAttributes, lInitialCount, lMaximumCount, lpName); | |
161 | } | |
162 | ||
163 | BOOST_FORCEINLINE HANDLE_ open_semaphore(DWORD_ dwDesiredAccess, BOOL_ bInheritHandle, LPCWSTR_ lpName) | |
164 | { | |
165 | return ::OpenSemaphoreW(dwDesiredAccess, bInheritHandle, lpName); | |
166 | } | |
167 | ||
168 | BOOST_FORCEINLINE HANDLE_ create_anonymous_semaphore(SECURITY_ATTRIBUTES_* lpSemaphoreAttributes, LONG_ lInitialCount, LONG_ lMaximumCount) | |
169 | { | |
170 | return winapi::CreateSemaphoreW(lpSemaphoreAttributes, lInitialCount, lMaximumCount, 0); | |
171 | } | |
172 | ||
173 | } | |
174 | } | |
175 | } | |
176 | ||
177 | #endif // BOOST_DETAIL_WINAPI_SEMAPHORE_HPP |