condition_variable.hpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. // condition_variable.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_CONDITION_VARIABLE_HPP
  7. #define BOOST_DETAIL_WINAPI_CONDITION_VARIABLE_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. #include <boost/detail/winapi/basic_types.hpp>
  14. #if !defined( BOOST_USE_WINDOWS_H )
  15. extern "C" {
  16. struct _RTL_CONDITION_VARIABLE;
  17. struct _RTL_CRITICAL_SECTION;
  18. struct _RTL_SRWLOCK;
  19. BOOST_SYMBOL_IMPORT boost::detail::winapi::VOID_ WINAPI
  20. InitializeConditionVariable(::_RTL_CONDITION_VARIABLE* ConditionVariable);
  21. BOOST_SYMBOL_IMPORT boost::detail::winapi::VOID_ WINAPI
  22. WakeConditionVariable(::_RTL_CONDITION_VARIABLE* ConditionVariable);
  23. BOOST_SYMBOL_IMPORT boost::detail::winapi::VOID_ WINAPI
  24. WakeAllConditionVariable(::_RTL_CONDITION_VARIABLE* ConditionVariable);
  25. BOOST_SYMBOL_IMPORT boost::detail::winapi::BOOL_ WINAPI
  26. SleepConditionVariableCS(
  27. ::_RTL_CONDITION_VARIABLE* ConditionVariable,
  28. ::_RTL_CRITICAL_SECTION* CriticalSection,
  29. boost::detail::winapi::DWORD_ dwMilliseconds);
  30. BOOST_SYMBOL_IMPORT boost::detail::winapi::BOOL_ WINAPI
  31. SleepConditionVariableSRW(
  32. ::_RTL_CONDITION_VARIABLE* ConditionVariable,
  33. ::_RTL_SRWLOCK* SRWLock,
  34. boost::detail::winapi::DWORD_ dwMilliseconds,
  35. boost::detail::winapi::ULONG_ Flags);
  36. }
  37. #endif
  38. namespace boost {
  39. namespace detail {
  40. namespace winapi {
  41. typedef struct BOOST_DETAIL_WINAPI_MAY_ALIAS _RTL_CONDITION_VARIABLE {
  42. PVOID_ Ptr;
  43. } CONDITION_VARIABLE_, *PCONDITION_VARIABLE_;
  44. #if defined( BOOST_USE_WINDOWS_H )
  45. #define BOOST_DETAIL_WINAPI_CONDITION_VARIABLE_INIT CONDITION_VARIABLE_INIT
  46. #else
  47. #define BOOST_DETAIL_WINAPI_CONDITION_VARIABLE {0}
  48. #endif
  49. struct _RTL_CRITICAL_SECTION;
  50. struct _RTL_SRWLOCK;
  51. BOOST_FORCEINLINE VOID_ InitializeConditionVariable(PCONDITION_VARIABLE_ ConditionVariable)
  52. {
  53. ::InitializeConditionVariable(reinterpret_cast< ::_RTL_CONDITION_VARIABLE* >(ConditionVariable));
  54. }
  55. BOOST_FORCEINLINE VOID_ WakeConditionVariable(PCONDITION_VARIABLE_ ConditionVariable)
  56. {
  57. ::WakeConditionVariable(reinterpret_cast< ::_RTL_CONDITION_VARIABLE* >(ConditionVariable));
  58. }
  59. BOOST_FORCEINLINE VOID_ WakeAllConditionVariable(PCONDITION_VARIABLE_ ConditionVariable)
  60. {
  61. ::WakeAllConditionVariable(reinterpret_cast< ::_RTL_CONDITION_VARIABLE* >(ConditionVariable));
  62. }
  63. BOOST_FORCEINLINE BOOL_ SleepConditionVariableCS(
  64. PCONDITION_VARIABLE_ ConditionVariable,
  65. _RTL_CRITICAL_SECTION* CriticalSection,
  66. DWORD_ dwMilliseconds)
  67. {
  68. return ::SleepConditionVariableCS(
  69. reinterpret_cast< ::_RTL_CONDITION_VARIABLE* >(ConditionVariable),
  70. reinterpret_cast< ::_RTL_CRITICAL_SECTION* >(CriticalSection),
  71. dwMilliseconds);
  72. }
  73. BOOST_FORCEINLINE BOOL_ SleepConditionVariableSRW(
  74. PCONDITION_VARIABLE_ ConditionVariable,
  75. _RTL_SRWLOCK* SRWLock,
  76. DWORD_ dwMilliseconds,
  77. ULONG_ Flags)
  78. {
  79. return ::SleepConditionVariableSRW(
  80. reinterpret_cast< ::_RTL_CONDITION_VARIABLE* >(ConditionVariable),
  81. reinterpret_cast< ::_RTL_SRWLOCK* >(SRWLock),
  82. dwMilliseconds,
  83. Flags);
  84. }
  85. #if defined( BOOST_USE_WINDOWS_H )
  86. const ULONG_ CONDITION_VARIABLE_LOCKMODE_SHARED_ = CONDITION_VARIABLE_LOCKMODE_SHARED;
  87. #else // defined( BOOST_USE_WINDOWS_H )
  88. const ULONG_ CONDITION_VARIABLE_LOCKMODE_SHARED_ = 0x00000001;
  89. #endif // defined( BOOST_USE_WINDOWS_H )
  90. const ULONG_ condition_variable_lockmode_shared = CONDITION_VARIABLE_LOCKMODE_SHARED_;
  91. }
  92. }
  93. }
  94. #endif // BOOST_USE_WINAPI_VERSION >= BOOST_WINAPI_VERSION_WIN6
  95. #endif // BOOST_DETAIL_WINAPI_CONDITION_VARIABLE_HPP