srw_lock.hpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. #ifndef BOOST_WINAPI_SRW_LOCK_HPP_INCLUDED_
  9. #define BOOST_WINAPI_SRW_LOCK_HPP_INCLUDED_
  10. #include <boost/winapi/config.hpp>
  11. #ifdef BOOST_HAS_PRAGMA_ONCE
  12. #pragma once
  13. #endif
  14. #if BOOST_USE_WINAPI_VERSION < BOOST_WINAPI_VERSION_WIN6 \
  15. || (defined(_MSC_VER) && _MSC_VER < 1600)
  16. // Windows SDK 6.0A, which is used by MSVC 9, does not have TryAcquireSRWLock* neither in headers nor in .lib files,
  17. // although the functions are present in later SDKs since Windows API version 6.
  18. #define BOOST_WINAPI_NO_TRY_ACQUIRE_SRWLOCK
  19. #endif
  20. #if BOOST_USE_WINAPI_VERSION >= BOOST_WINAPI_VERSION_WIN6
  21. #include <boost/winapi/basic_types.hpp>
  22. #include <boost/winapi/detail/header.hpp>
  23. #if !defined( BOOST_USE_WINDOWS_H )
  24. extern "C" {
  25. struct _RTL_SRWLOCK;
  26. BOOST_WINAPI_IMPORT boost::winapi::VOID_ BOOST_WINAPI_WINAPI_CC
  27. InitializeSRWLock(::_RTL_SRWLOCK* SRWLock);
  28. BOOST_WINAPI_IMPORT boost::winapi::VOID_ BOOST_WINAPI_WINAPI_CC
  29. ReleaseSRWLockExclusive(::_RTL_SRWLOCK* SRWLock);
  30. BOOST_WINAPI_IMPORT boost::winapi::VOID_ BOOST_WINAPI_WINAPI_CC
  31. ReleaseSRWLockShared(::_RTL_SRWLOCK* SRWLock);
  32. BOOST_WINAPI_IMPORT boost::winapi::VOID_ BOOST_WINAPI_WINAPI_CC
  33. AcquireSRWLockExclusive(::_RTL_SRWLOCK* SRWLock);
  34. BOOST_WINAPI_IMPORT boost::winapi::VOID_ BOOST_WINAPI_WINAPI_CC
  35. AcquireSRWLockShared(::_RTL_SRWLOCK* SRWLock);
  36. #if !defined( BOOST_WINAPI_NO_TRY_ACQUIRE_SRWLOCK )
  37. BOOST_WINAPI_IMPORT boost::winapi::BOOLEAN_ BOOST_WINAPI_WINAPI_CC
  38. TryAcquireSRWLockExclusive(::_RTL_SRWLOCK* SRWLock);
  39. BOOST_WINAPI_IMPORT boost::winapi::BOOLEAN_ BOOST_WINAPI_WINAPI_CC
  40. TryAcquireSRWLockShared(::_RTL_SRWLOCK* SRWLock);
  41. #endif
  42. } // extern "C"
  43. #endif
  44. namespace boost {
  45. namespace winapi {
  46. typedef struct BOOST_MAY_ALIAS _RTL_SRWLOCK {
  47. PVOID_ Ptr;
  48. } SRWLOCK_, *PSRWLOCK_;
  49. #if defined( BOOST_USE_WINDOWS_H )
  50. #define BOOST_WINAPI_SRWLOCK_INIT SRWLOCK_INIT
  51. #else
  52. #define BOOST_WINAPI_SRWLOCK_INIT {0}
  53. #endif
  54. BOOST_FORCEINLINE VOID_ InitializeSRWLock(PSRWLOCK_ SRWLock)
  55. {
  56. ::InitializeSRWLock(reinterpret_cast< ::_RTL_SRWLOCK* >(SRWLock));
  57. }
  58. BOOST_FORCEINLINE VOID_ ReleaseSRWLockExclusive(PSRWLOCK_ SRWLock)
  59. {
  60. ::ReleaseSRWLockExclusive(reinterpret_cast< ::_RTL_SRWLOCK* >(SRWLock));
  61. }
  62. BOOST_FORCEINLINE VOID_ ReleaseSRWLockShared(PSRWLOCK_ SRWLock)
  63. {
  64. ::ReleaseSRWLockShared(reinterpret_cast< ::_RTL_SRWLOCK* >(SRWLock));
  65. }
  66. BOOST_FORCEINLINE VOID_ AcquireSRWLockExclusive(PSRWLOCK_ SRWLock)
  67. {
  68. ::AcquireSRWLockExclusive(reinterpret_cast< ::_RTL_SRWLOCK* >(SRWLock));
  69. }
  70. BOOST_FORCEINLINE VOID_ AcquireSRWLockShared(PSRWLOCK_ SRWLock)
  71. {
  72. ::AcquireSRWLockShared(reinterpret_cast< ::_RTL_SRWLOCK* >(SRWLock));
  73. }
  74. #if !defined( BOOST_WINAPI_NO_TRY_ACQUIRE_SRWLOCK )
  75. BOOST_FORCEINLINE BOOLEAN_ TryAcquireSRWLockExclusive(PSRWLOCK_ SRWLock)
  76. {
  77. return ::TryAcquireSRWLockExclusive(reinterpret_cast< ::_RTL_SRWLOCK* >(SRWLock));
  78. }
  79. BOOST_FORCEINLINE BOOLEAN_ TryAcquireSRWLockShared(PSRWLOCK_ SRWLock)
  80. {
  81. return ::TryAcquireSRWLockShared(reinterpret_cast< ::_RTL_SRWLOCK* >(SRWLock));
  82. }
  83. #endif
  84. }
  85. }
  86. #include <boost/winapi/detail/footer.hpp>
  87. #endif // BOOST_USE_WINAPI_VERSION >= BOOST_WINAPI_VERSION_WIN6
  88. #endif // BOOST_WINAPI_SRW_LOCK_HPP_INCLUDED_