2 * Copyright 2010 Vicente J. Botet Escriba
3 * Copyright 2015, 2017 Andrey Semashev
5 * Distributed under the Boost Software License, Version 1.0.
6 * See http://www.boost.org/LICENSE_1_0.txt
9 #ifndef BOOST_WINAPI_MUTEX_HPP_INCLUDED_
10 #define BOOST_WINAPI_MUTEX_HPP_INCLUDED_
12 #include <boost/winapi/basic_types.hpp>
14 #ifdef BOOST_HAS_PRAGMA_ONCE
18 #if !defined( BOOST_USE_WINDOWS_H ) && BOOST_WINAPI_PARTITION_APP_SYSTEM
20 #if !defined( BOOST_NO_ANSI_APIS )
21 BOOST_SYMBOL_IMPORT boost::winapi::HANDLE_ WINAPI
23 ::_SECURITY_ATTRIBUTES* lpMutexAttributes,
24 boost::winapi::BOOL_ bInitialOwner,
25 boost::winapi::LPCSTR_ lpName);
28 BOOST_SYMBOL_IMPORT boost::winapi::HANDLE_ WINAPI
30 ::_SECURITY_ATTRIBUTES* lpMutexAttributes,
31 boost::winapi::BOOL_ bInitialOwner,
32 boost::winapi::LPCWSTR_ lpName);
34 #endif // !defined( BOOST_USE_WINDOWS_H ) && BOOST_WINAPI_PARTITION_APP_SYSTEM
36 #if !defined( BOOST_USE_WINDOWS_H )
38 #if !defined( BOOST_NO_ANSI_APIS )
39 #if BOOST_USE_WINAPI_VERSION >= BOOST_WINAPI_VERSION_WIN6
40 BOOST_SYMBOL_IMPORT boost::winapi::HANDLE_ WINAPI
42 ::_SECURITY_ATTRIBUTES* lpMutexAttributes,
43 boost::winapi::LPCSTR_ lpName,
44 boost::winapi::DWORD_ dwFlags,
45 boost::winapi::DWORD_ dwDesiredAccess);
48 BOOST_SYMBOL_IMPORT boost::winapi::HANDLE_ WINAPI
50 boost::winapi::DWORD_ dwDesiredAccess,
51 boost::winapi::BOOL_ bInheritHandle,
52 boost::winapi::LPCSTR_ lpName);
53 #endif // !defined( BOOST_NO_ANSI_APIS )
55 #if BOOST_USE_WINAPI_VERSION >= BOOST_WINAPI_VERSION_WIN6
56 BOOST_SYMBOL_IMPORT boost::winapi::HANDLE_ WINAPI
58 ::_SECURITY_ATTRIBUTES* lpMutexAttributes,
59 boost::winapi::LPCWSTR_ lpName,
60 boost::winapi::DWORD_ dwFlags,
61 boost::winapi::DWORD_ dwDesiredAccess);
64 BOOST_SYMBOL_IMPORT boost::winapi::HANDLE_ WINAPI
66 boost::winapi::DWORD_ dwDesiredAccess,
67 boost::winapi::BOOL_ bInheritHandle,
68 boost::winapi::LPCWSTR_ lpName);
70 BOOST_SYMBOL_IMPORT boost::winapi::BOOL_ WINAPI
71 ReleaseMutex(boost::winapi::HANDLE_ hMutex);
78 #if !defined( BOOST_NO_ANSI_APIS )
84 #if defined( BOOST_USE_WINDOWS_H )
86 const DWORD_ MUTEX_ALL_ACCESS_ = MUTEX_ALL_ACCESS;
87 const DWORD_ MUTEX_MODIFY_STATE_ = MUTEX_MODIFY_STATE;
88 #if BOOST_USE_WINAPI_VERSION >= BOOST_WINAPI_VERSION_WIN6
89 const DWORD_ CREATE_MUTEX_INITIAL_OWNER_ = CREATE_MUTEX_INITIAL_OWNER;
92 #else // defined( BOOST_USE_WINDOWS_H )
94 const DWORD_ MUTEX_ALL_ACCESS_ = 0x001F0001;
95 const DWORD_ MUTEX_MODIFY_STATE_ = 0x00000001;
96 #if BOOST_USE_WINAPI_VERSION >= BOOST_WINAPI_VERSION_WIN6
97 const DWORD_ CREATE_MUTEX_INITIAL_OWNER_ = 0x00000001;
100 #endif // defined( BOOST_USE_WINDOWS_H )
102 const DWORD_ mutex_all_access = MUTEX_ALL_ACCESS_;
103 const DWORD_ mutex_modify_state = MUTEX_MODIFY_STATE_;
104 #if BOOST_USE_WINAPI_VERSION >= BOOST_WINAPI_VERSION_WIN6
105 const DWORD_ create_mutex_initial_owner = CREATE_MUTEX_INITIAL_OWNER_;
108 #if !defined( BOOST_NO_ANSI_APIS )
109 BOOST_FORCEINLINE HANDLE_ CreateMutexA(SECURITY_ATTRIBUTES_* lpMutexAttributes, BOOL_ bInitialOwner, LPCSTR_ lpName)
111 #if !BOOST_WINAPI_PARTITION_APP_SYSTEM && BOOST_USE_WINAPI_VERSION >= BOOST_WINAPI_VERSION_WIN6
112 const DWORD_ flags = bInitialOwner ? create_mutex_initial_owner : 0u;
113 return ::CreateMutexExA(reinterpret_cast< ::_SECURITY_ATTRIBUTES* >(lpMutexAttributes), lpName, flags, mutex_all_access);
115 return ::CreateMutexA(reinterpret_cast< ::_SECURITY_ATTRIBUTES* >(lpMutexAttributes), bInitialOwner, lpName);
119 #if BOOST_USE_WINAPI_VERSION >= BOOST_WINAPI_VERSION_WIN6
120 BOOST_FORCEINLINE HANDLE_ CreateMutexExA(
121 SECURITY_ATTRIBUTES_* lpMutexAttributes,
124 DWORD_ dwDesiredAccess)
126 return ::CreateMutexExA(reinterpret_cast< ::_SECURITY_ATTRIBUTES* >(lpMutexAttributes), lpName, dwFlags, dwDesiredAccess);
131 BOOST_FORCEINLINE HANDLE_ CreateMutexW(SECURITY_ATTRIBUTES_* lpMutexAttributes, BOOL_ bInitialOwner, LPCWSTR_ lpName)
133 #if !BOOST_WINAPI_PARTITION_APP_SYSTEM && BOOST_USE_WINAPI_VERSION >= BOOST_WINAPI_VERSION_WIN6
134 const DWORD_ flags = bInitialOwner ? create_mutex_initial_owner : 0u;
135 return ::CreateMutexExW(reinterpret_cast< ::_SECURITY_ATTRIBUTES* >(lpMutexAttributes), lpName, flags, mutex_all_access);
137 return ::CreateMutexW(reinterpret_cast< ::_SECURITY_ATTRIBUTES* >(lpMutexAttributes), bInitialOwner, lpName);
141 #if BOOST_USE_WINAPI_VERSION >= BOOST_WINAPI_VERSION_WIN6
142 BOOST_FORCEINLINE HANDLE_ CreateMutexExW(
143 SECURITY_ATTRIBUTES_* lpMutexAttributes,
146 DWORD_ dwDesiredAccess)
148 return ::CreateMutexExW(reinterpret_cast< ::_SECURITY_ATTRIBUTES* >(lpMutexAttributes), lpName, dwFlags, dwDesiredAccess);
152 #if !defined( BOOST_NO_ANSI_APIS )
153 BOOST_FORCEINLINE HANDLE_ create_mutex(SECURITY_ATTRIBUTES_* lpAttributes, BOOL_ bInitialOwner, LPCSTR_ lpName)
155 return winapi::CreateMutexA(lpAttributes, bInitialOwner, lpName);
158 BOOST_FORCEINLINE HANDLE_ open_mutex(DWORD_ dwDesiredAccess, BOOL_ bInheritHandle, LPCSTR_ lpName)
160 return ::OpenMutexA(dwDesiredAccess, bInheritHandle, lpName);
164 BOOST_FORCEINLINE HANDLE_ create_mutex(SECURITY_ATTRIBUTES_* lpAttributes, BOOL_ bInitialOwner, LPCWSTR_ lpName)
166 return winapi::CreateMutexW(lpAttributes, bInitialOwner, lpName);
169 BOOST_FORCEINLINE HANDLE_ open_mutex(DWORD_ dwDesiredAccess, BOOL_ bInheritHandle, LPCWSTR_ lpName)
171 return ::OpenMutexW(dwDesiredAccess, bInheritHandle, lpName);
174 BOOST_FORCEINLINE HANDLE_ create_anonymous_mutex(SECURITY_ATTRIBUTES_* lpAttributes, BOOL_ bInitialOwner)
176 return winapi::CreateMutexW(lpAttributes, bInitialOwner, 0);
182 #endif // BOOST_WINAPI_MUTEX_HPP_INCLUDED_