srw_lock.hpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. // srw_lock.hpp --------------------------------------------------------------//
  2. // Copyright 2010 Vicente J. Botet Escriba
  3. // Copyright 2015 Andrey Semashev
  4. // Distributed under the Boost Software License, Version 1.0.
  5. // See http://www.boost.org/LICENSE_1_0.txt
  6. #ifndef BOOST_DETAIL_WINAPI_SRW_LOCK_HPP
  7. #define BOOST_DETAIL_WINAPI_SRW_LOCK_HPP
  8. #include <boost/detail/winapi/config.hpp>
  9. #ifdef BOOST_HAS_PRAGMA_ONCE
  10. #pragma once
  11. #endif
  12. #if BOOST_USE_WINAPI_VERSION < BOOST_WINAPI_VERSION_WIN6 \
  13. || (defined(_MSC_VER) && _MSC_VER < 1600)
  14. // Windows SDK 6.0A, which is used by MSVC 9, does not have TryAcquireSRWLock* neither in headers nor in .lib files,
  15. // although the functions are present in later SDKs since Windows API version 6.
  16. #define BOOST_WINAPI_NO_TRY_ACQUIRE_SRWLOCK
  17. #endif
  18. #if BOOST_USE_WINAPI_VERSION >= BOOST_WINAPI_VERSION_WIN6
  19. #include <boost/detail/winapi/basic_types.hpp>
  20. #if !defined( BOOST_USE_WINDOWS_H )
  21. extern "C" {
  22. struct _RTL_SRWLOCK;
  23. BOOST_SYMBOL_IMPORT boost::detail::winapi::VOID_ WINAPI
  24. InitializeSRWLock(::_RTL_SRWLOCK* SRWLock);
  25. BOOST_SYMBOL_IMPORT boost::detail::winapi::VOID_ WINAPI
  26. ReleaseSRWLockExclusive(::_RTL_SRWLOCK* SRWLock);
  27. BOOST_SYMBOL_IMPORT boost::detail::winapi::VOID_ WINAPI
  28. ReleaseSRWLockShared(::_RTL_SRWLOCK* SRWLock);
  29. BOOST_SYMBOL_IMPORT boost::detail::winapi::VOID_ WINAPI
  30. AcquireSRWLockExclusive(::_RTL_SRWLOCK* SRWLock);
  31. BOOST_SYMBOL_IMPORT boost::detail::winapi::VOID_ WINAPI
  32. AcquireSRWLockShared(::_RTL_SRWLOCK* SRWLock);
  33. #if !defined( BOOST_WINAPI_NO_TRY_ACQUIRE_SRWLOCK )
  34. BOOST_SYMBOL_IMPORT boost::detail::winapi::BOOLEAN_ WINAPI
  35. TryAcquireSRWLockExclusive(::_RTL_SRWLOCK* SRWLock);
  36. BOOST_SYMBOL_IMPORT boost::detail::winapi::BOOLEAN_ WINAPI
  37. TryAcquireSRWLockShared(::_RTL_SRWLOCK* SRWLock);
  38. #endif
  39. }
  40. #endif
  41. namespace boost {
  42. namespace detail {
  43. namespace winapi {
  44. typedef struct BOOST_DETAIL_WINAPI_MAY_ALIAS _RTL_SRWLOCK {
  45. PVOID_ Ptr;
  46. } SRWLOCK_, *PSRWLOCK_;
  47. #if defined( BOOST_USE_WINDOWS_H )
  48. #define BOOST_DETAIL_WINAPI_SRWLOCK_INIT SRWLOCK_INIT
  49. #else
  50. #define BOOST_DETAIL_WINAPI_SRWLOCK_INIT {0}
  51. #endif
  52. BOOST_FORCEINLINE VOID_ InitializeSRWLock(PSRWLOCK_ SRWLock)
  53. {
  54. ::InitializeSRWLock(reinterpret_cast< ::_RTL_SRWLOCK* >(SRWLock));
  55. }
  56. BOOST_FORCEINLINE VOID_ ReleaseSRWLockExclusive(PSRWLOCK_ SRWLock)
  57. {
  58. ::ReleaseSRWLockExclusive(reinterpret_cast< ::_RTL_SRWLOCK* >(SRWLock));
  59. }
  60. BOOST_FORCEINLINE VOID_ ReleaseSRWLockShared(PSRWLOCK_ SRWLock)
  61. {
  62. ::ReleaseSRWLockShared(reinterpret_cast< ::_RTL_SRWLOCK* >(SRWLock));
  63. }
  64. BOOST_FORCEINLINE VOID_ AcquireSRWLockExclusive(PSRWLOCK_ SRWLock)
  65. {
  66. ::AcquireSRWLockExclusive(reinterpret_cast< ::_RTL_SRWLOCK* >(SRWLock));
  67. }
  68. BOOST_FORCEINLINE VOID_ AcquireSRWLockShared(PSRWLOCK_ SRWLock)
  69. {
  70. ::AcquireSRWLockShared(reinterpret_cast< ::_RTL_SRWLOCK* >(SRWLock));
  71. }
  72. #if !defined( BOOST_WINAPI_NO_TRY_ACQUIRE_SRWLOCK )
  73. BOOST_FORCEINLINE BOOLEAN_ TryAcquireSRWLockExclusive(PSRWLOCK_ SRWLock)
  74. {
  75. return ::TryAcquireSRWLockExclusive(reinterpret_cast< ::_RTL_SRWLOCK* >(SRWLock));
  76. }
  77. BOOST_FORCEINLINE BOOLEAN_ TryAcquireSRWLockShared(PSRWLOCK_ SRWLock)
  78. {
  79. return ::TryAcquireSRWLockShared(reinterpret_cast< ::_RTL_SRWLOCK* >(SRWLock));
  80. }
  81. #endif
  82. }
  83. }
  84. }
  85. #endif // BOOST_USE_WINAPI_VERSION >= BOOST_WINAPI_VERSION_WIN6
  86. #endif // BOOST_DETAIL_WINAPI_SRW_LOCK_HPP