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_SRW_LOCK_HPP_INCLUDED_ 10 #define BOOST_WINAPI_SRW_LOCK_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 || (defined(_MSC_VER) && _MSC_VER < 1600) 20 // Windows SDK 6.0A, which is used by MSVC 9, does not have TryAcquireSRWLock* neither in headers nor in .lib files, 21 // although the functions are present in later SDKs since Windows API version 6. 22 #define BOOST_WINAPI_NO_TRY_ACQUIRE_SRWLOCK 23 #endif 24 25 #if BOOST_USE_WINAPI_VERSION >= BOOST_WINAPI_VERSION_WIN6 26 27 #include <boost/winapi/basic_types.hpp> 28 #include <boost/winapi/detail/header.hpp> 29 30 #if !defined( BOOST_USE_WINDOWS_H ) 31 extern "C" { 32 struct _RTL_SRWLOCK; 33 34 BOOST_WINAPI_IMPORT boost::winapi::VOID_ BOOST_WINAPI_WINAPI_CC 35 InitializeSRWLock(::_RTL_SRWLOCK* SRWLock); 36 37 BOOST_WINAPI_IMPORT boost::winapi::VOID_ BOOST_WINAPI_WINAPI_CC 38 ReleaseSRWLockExclusive(::_RTL_SRWLOCK* SRWLock); 39 40 BOOST_WINAPI_IMPORT boost::winapi::VOID_ BOOST_WINAPI_WINAPI_CC 41 ReleaseSRWLockShared(::_RTL_SRWLOCK* SRWLock); 42 43 BOOST_WINAPI_IMPORT boost::winapi::VOID_ BOOST_WINAPI_WINAPI_CC 44 AcquireSRWLockExclusive(::_RTL_SRWLOCK* SRWLock); 45 46 BOOST_WINAPI_IMPORT boost::winapi::VOID_ BOOST_WINAPI_WINAPI_CC 47 AcquireSRWLockShared(::_RTL_SRWLOCK* SRWLock); 48 49 #if !defined( BOOST_WINAPI_NO_TRY_ACQUIRE_SRWLOCK ) 50 BOOST_WINAPI_IMPORT boost::winapi::BOOLEAN_ BOOST_WINAPI_WINAPI_CC 51 TryAcquireSRWLockExclusive(::_RTL_SRWLOCK* SRWLock); 52 53 BOOST_WINAPI_IMPORT boost::winapi::BOOLEAN_ BOOST_WINAPI_WINAPI_CC 54 TryAcquireSRWLockShared(::_RTL_SRWLOCK* SRWLock); 55 #endif 56 } // extern "C" 57 #endif 58 59 namespace boost { 60 namespace winapi { 61 62 typedef struct BOOST_MAY_ALIAS _RTL_SRWLOCK { 63 PVOID_ Ptr; 64 } SRWLOCK_, *PSRWLOCK_; 65 66 #if defined( BOOST_USE_WINDOWS_H ) 67 #define BOOST_WINAPI_SRWLOCK_INIT SRWLOCK_INIT 68 #else 69 #define BOOST_WINAPI_SRWLOCK_INIT {0} 70 #endif 71 InitializeSRWLock(PSRWLOCK_ SRWLock)72BOOST_FORCEINLINE VOID_ InitializeSRWLock(PSRWLOCK_ SRWLock) 73 { 74 ::InitializeSRWLock(reinterpret_cast< ::_RTL_SRWLOCK* >(SRWLock)); 75 } 76 ReleaseSRWLockExclusive(PSRWLOCK_ SRWLock)77BOOST_FORCEINLINE VOID_ ReleaseSRWLockExclusive(PSRWLOCK_ SRWLock) 78 { 79 ::ReleaseSRWLockExclusive(reinterpret_cast< ::_RTL_SRWLOCK* >(SRWLock)); 80 } 81 ReleaseSRWLockShared(PSRWLOCK_ SRWLock)82BOOST_FORCEINLINE VOID_ ReleaseSRWLockShared(PSRWLOCK_ SRWLock) 83 { 84 ::ReleaseSRWLockShared(reinterpret_cast< ::_RTL_SRWLOCK* >(SRWLock)); 85 } 86 AcquireSRWLockExclusive(PSRWLOCK_ SRWLock)87BOOST_FORCEINLINE VOID_ AcquireSRWLockExclusive(PSRWLOCK_ SRWLock) 88 { 89 ::AcquireSRWLockExclusive(reinterpret_cast< ::_RTL_SRWLOCK* >(SRWLock)); 90 } 91 AcquireSRWLockShared(PSRWLOCK_ SRWLock)92BOOST_FORCEINLINE VOID_ AcquireSRWLockShared(PSRWLOCK_ SRWLock) 93 { 94 ::AcquireSRWLockShared(reinterpret_cast< ::_RTL_SRWLOCK* >(SRWLock)); 95 } 96 97 #if !defined( BOOST_WINAPI_NO_TRY_ACQUIRE_SRWLOCK ) TryAcquireSRWLockExclusive(PSRWLOCK_ SRWLock)98BOOST_FORCEINLINE BOOLEAN_ TryAcquireSRWLockExclusive(PSRWLOCK_ SRWLock) 99 { 100 return ::TryAcquireSRWLockExclusive(reinterpret_cast< ::_RTL_SRWLOCK* >(SRWLock)); 101 } 102 TryAcquireSRWLockShared(PSRWLOCK_ SRWLock)103BOOST_FORCEINLINE BOOLEAN_ TryAcquireSRWLockShared(PSRWLOCK_ SRWLock) 104 { 105 return ::TryAcquireSRWLockShared(reinterpret_cast< ::_RTL_SRWLOCK* >(SRWLock)); 106 } 107 #endif 108 109 } 110 } 111 112 #include <boost/winapi/detail/footer.hpp> 113 114 #endif // BOOST_USE_WINAPI_VERSION >= BOOST_WINAPI_VERSION_WIN6 115 116 #endif // BOOST_WINAPI_SRW_LOCK_HPP_INCLUDED_ 117