condition_variable.hpp 3.8 KB

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