waitable_timer.hpp 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. /*
  2. * Copyright 2013 Andrey Semashev
  3. *
  4. * Distributed under the Boost Software License, Version 1.0.
  5. * See http://www.boost.org/LICENSE_1_0.txt
  6. */
  7. #ifndef BOOST_WINAPI_WAITABLE_TIMER_HPP_INCLUDED_
  8. #define BOOST_WINAPI_WAITABLE_TIMER_HPP_INCLUDED_
  9. #include <boost/winapi/basic_types.hpp>
  10. #ifdef BOOST_HAS_PRAGMA_ONCE
  11. #pragma once
  12. #endif
  13. #if BOOST_WINAPI_PARTITION_APP_SYSTEM
  14. #include <boost/winapi/detail/header.hpp>
  15. #if !defined( BOOST_USE_WINDOWS_H )
  16. extern "C" {
  17. typedef boost::winapi::VOID_
  18. (BOOST_WINAPI_WINAPI_CC *PTIMERAPCROUTINE)(
  19. boost::winapi::LPVOID_ lpArgToCompletionRoutine,
  20. boost::winapi::DWORD_ dwTimerLowValue,
  21. boost::winapi::DWORD_ dwTimerHighValue);
  22. #if !defined( BOOST_NO_ANSI_APIS )
  23. BOOST_WINAPI_IMPORT boost::winapi::HANDLE_ BOOST_WINAPI_WINAPI_CC
  24. CreateWaitableTimerA(
  25. ::_SECURITY_ATTRIBUTES* lpTimerAttributes,
  26. boost::winapi::BOOL_ bManualReset,
  27. boost::winapi::LPCSTR_ lpTimerName);
  28. BOOST_WINAPI_IMPORT boost::winapi::HANDLE_ BOOST_WINAPI_WINAPI_CC
  29. OpenWaitableTimerA(
  30. boost::winapi::DWORD_ dwDesiredAccess,
  31. boost::winapi::BOOL_ bInheritHandle,
  32. boost::winapi::LPCSTR_ lpTimerName);
  33. #endif
  34. BOOST_WINAPI_IMPORT boost::winapi::HANDLE_ BOOST_WINAPI_WINAPI_CC
  35. CreateWaitableTimerW(
  36. ::_SECURITY_ATTRIBUTES* lpTimerAttributes,
  37. boost::winapi::BOOL_ bManualReset,
  38. boost::winapi::LPCWSTR_ lpTimerName);
  39. BOOST_WINAPI_IMPORT boost::winapi::HANDLE_ BOOST_WINAPI_WINAPI_CC
  40. OpenWaitableTimerW(
  41. boost::winapi::DWORD_ dwDesiredAccess,
  42. boost::winapi::BOOL_ bInheritHandle,
  43. boost::winapi::LPCWSTR_ lpTimerName);
  44. BOOST_WINAPI_IMPORT boost::winapi::BOOL_ BOOST_WINAPI_WINAPI_CC
  45. SetWaitableTimer(
  46. boost::winapi::HANDLE_ hTimer,
  47. const ::_LARGE_INTEGER* lpDueTime,
  48. boost::winapi::LONG_ lPeriod,
  49. PTIMERAPCROUTINE pfnCompletionRoutine,
  50. boost::winapi::LPVOID_ lpArgToCompletionRoutine,
  51. boost::winapi::BOOL_ fResume);
  52. BOOST_WINAPI_IMPORT boost::winapi::BOOL_ BOOST_WINAPI_WINAPI_CC
  53. CancelWaitableTimer(boost::winapi::HANDLE_ hTimer);
  54. } // extern "C"
  55. #endif
  56. namespace boost {
  57. namespace winapi {
  58. typedef ::PTIMERAPCROUTINE PTIMERAPCROUTINE_;
  59. #if !defined( BOOST_NO_ANSI_APIS )
  60. using ::OpenWaitableTimerA;
  61. #endif
  62. using ::OpenWaitableTimerW;
  63. using ::CancelWaitableTimer;
  64. #if defined( BOOST_USE_WINDOWS_H )
  65. BOOST_CONSTEXPR_OR_CONST DWORD_ TIMER_ALL_ACCESS_ = TIMER_ALL_ACCESS;
  66. BOOST_CONSTEXPR_OR_CONST DWORD_ TIMER_MODIFY_STATE_ = TIMER_MODIFY_STATE;
  67. BOOST_CONSTEXPR_OR_CONST DWORD_ TIMER_QUERY_STATE_ = TIMER_QUERY_STATE;
  68. #else // defined( BOOST_USE_WINDOWS_H )
  69. BOOST_CONSTEXPR_OR_CONST DWORD_ TIMER_ALL_ACCESS_ = 0x001F0003;
  70. BOOST_CONSTEXPR_OR_CONST DWORD_ TIMER_MODIFY_STATE_ = 0x00000002;
  71. BOOST_CONSTEXPR_OR_CONST DWORD_ TIMER_QUERY_STATE_ = 0x00000001;
  72. #endif // defined( BOOST_USE_WINDOWS_H )
  73. BOOST_CONSTEXPR_OR_CONST DWORD_ timer_all_access = TIMER_ALL_ACCESS_;
  74. BOOST_CONSTEXPR_OR_CONST DWORD_ timer_modify_state = TIMER_MODIFY_STATE_;
  75. BOOST_CONSTEXPR_OR_CONST DWORD_ timer_query_state = TIMER_QUERY_STATE_;
  76. #if !defined( BOOST_NO_ANSI_APIS )
  77. BOOST_FORCEINLINE HANDLE_ CreateWaitableTimerA(PSECURITY_ATTRIBUTES_ lpTimerAttributes, BOOL_ bManualReset, LPCSTR_ lpTimerName)
  78. {
  79. return ::CreateWaitableTimerA(reinterpret_cast< ::_SECURITY_ATTRIBUTES* >(lpTimerAttributes), bManualReset, lpTimerName);
  80. }
  81. #endif
  82. BOOST_FORCEINLINE HANDLE_ CreateWaitableTimerW(PSECURITY_ATTRIBUTES_ lpTimerAttributes, BOOL_ bManualReset, LPCWSTR_ lpTimerName)
  83. {
  84. return ::CreateWaitableTimerW(reinterpret_cast< ::_SECURITY_ATTRIBUTES* >(lpTimerAttributes), bManualReset, lpTimerName);
  85. }
  86. BOOST_FORCEINLINE BOOL_ SetWaitableTimer(
  87. HANDLE_ hTimer,
  88. const LARGE_INTEGER_* lpDueTime,
  89. LONG_ lPeriod,
  90. PTIMERAPCROUTINE_ pfnCompletionRoutine,
  91. LPVOID_ lpArgToCompletionRoutine,
  92. BOOL_ fResume)
  93. {
  94. return ::SetWaitableTimer(hTimer, reinterpret_cast< const ::_LARGE_INTEGER* >(lpDueTime), lPeriod, pfnCompletionRoutine, lpArgToCompletionRoutine, fResume);
  95. }
  96. #if !defined( BOOST_NO_ANSI_APIS )
  97. BOOST_FORCEINLINE HANDLE_ create_waitable_timer(PSECURITY_ATTRIBUTES_ lpTimerAttributes, BOOL_ bManualReset, LPCSTR_ lpTimerName)
  98. {
  99. return ::CreateWaitableTimerA(reinterpret_cast< ::_SECURITY_ATTRIBUTES* >(lpTimerAttributes), bManualReset, lpTimerName);
  100. }
  101. #endif
  102. BOOST_FORCEINLINE HANDLE_ create_waitable_timer(PSECURITY_ATTRIBUTES_ lpTimerAttributes, BOOL_ bManualReset, LPCWSTR_ lpTimerName)
  103. {
  104. return ::CreateWaitableTimerW(reinterpret_cast< ::_SECURITY_ATTRIBUTES* >(lpTimerAttributes), bManualReset, lpTimerName);
  105. }
  106. BOOST_FORCEINLINE HANDLE_ create_anonymous_waitable_timer(PSECURITY_ATTRIBUTES_ lpTimerAttributes, BOOL_ bManualReset)
  107. {
  108. #ifdef BOOST_NO_ANSI_APIS
  109. return ::CreateWaitableTimerW(reinterpret_cast< ::_SECURITY_ATTRIBUTES* >(lpTimerAttributes), bManualReset, 0);
  110. #else
  111. return ::CreateWaitableTimerA(reinterpret_cast< ::_SECURITY_ATTRIBUTES* >(lpTimerAttributes), bManualReset, 0);
  112. #endif
  113. }
  114. }
  115. }
  116. #include <boost/winapi/detail/footer.hpp>
  117. #endif // BOOST_WINAPI_PARTITION_APP_SYSTEM
  118. #endif // BOOST_WINAPI_WAITABLE_TIMER_HPP_INCLUDED_