thread_pool.hpp 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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_THREAD_POOL_HPP_INCLUDED_
  8. #define BOOST_WINAPI_THREAD_POOL_HPP_INCLUDED_
  9. #include <boost/winapi/config.hpp>
  10. #ifdef BOOST_HAS_PRAGMA_ONCE
  11. #pragma once
  12. #endif
  13. #if BOOST_USE_WINAPI_VERSION >= BOOST_WINAPI_VERSION_WIN2K
  14. #include <boost/winapi/basic_types.hpp>
  15. #include <boost/winapi/detail/header.hpp>
  16. #if !defined( BOOST_USE_WINDOWS_H )
  17. extern "C" {
  18. #if BOOST_WINAPI_PARTITION_DESKTOP
  19. typedef boost::winapi::VOID_ (BOOST_WINAPI_NTAPI_CC *WAITORTIMERCALLBACKFUNC)
  20. (boost::winapi::PVOID_, boost::winapi::BOOLEAN_);
  21. typedef WAITORTIMERCALLBACKFUNC WAITORTIMERCALLBACK;
  22. BOOST_WINAPI_IMPORT boost::winapi::BOOL_ BOOST_WINAPI_WINAPI_CC
  23. RegisterWaitForSingleObject(
  24. boost::winapi::PHANDLE_ phNewWaitObject,
  25. boost::winapi::HANDLE_ hObject,
  26. WAITORTIMERCALLBACK Callback,
  27. boost::winapi::PVOID_ Context,
  28. boost::winapi::ULONG_ dwMilliseconds,
  29. boost::winapi::ULONG_ dwFlags);
  30. #endif
  31. } // extern "C"
  32. #endif
  33. // MinGW is buggy - it is missing these function declarations for Win2000
  34. #if !defined( BOOST_USE_WINDOWS_H ) || (defined(BOOST_WINAPI_IS_MINGW) && BOOST_USE_WINAPI_VERSION < BOOST_WINAPI_VERSION_WINXP)
  35. extern "C" {
  36. #if BOOST_WINAPI_PARTITION_DESKTOP
  37. BOOST_WINAPI_IMPORT boost::winapi::BOOL_ BOOST_WINAPI_WINAPI_CC
  38. UnregisterWait(boost::winapi::HANDLE_ WaitHandle);
  39. #endif
  40. #if BOOST_WINAPI_PARTITION_DESKTOP || BOOST_WINAPI_PARTITION_SYSTEM
  41. BOOST_WINAPI_IMPORT boost::winapi::BOOL_ BOOST_WINAPI_WINAPI_CC
  42. UnregisterWaitEx(
  43. boost::winapi::HANDLE_ WaitHandle,
  44. boost::winapi::HANDLE_ CompletionEvent);
  45. #endif
  46. } // extern "C"
  47. #endif
  48. namespace boost {
  49. namespace winapi {
  50. #if BOOST_WINAPI_PARTITION_DESKTOP
  51. typedef ::WAITORTIMERCALLBACKFUNC WAITORTIMERCALLBACKFUNC_;
  52. typedef ::WAITORTIMERCALLBACK WAITORTIMERCALLBACK_;
  53. using ::RegisterWaitForSingleObject;
  54. using ::UnregisterWait;
  55. #endif
  56. #if BOOST_WINAPI_PARTITION_DESKTOP || BOOST_WINAPI_PARTITION_SYSTEM
  57. using ::UnregisterWaitEx;
  58. #endif
  59. #if defined( BOOST_USE_WINDOWS_H )
  60. BOOST_CONSTEXPR_OR_CONST ULONG_ WT_EXECUTEDEFAULT_ = WT_EXECUTEDEFAULT;
  61. BOOST_CONSTEXPR_OR_CONST ULONG_ WT_EXECUTEINIOTHREAD_ = WT_EXECUTEINIOTHREAD;
  62. #if defined( BOOST_WINAPI_IS_MINGW )
  63. BOOST_CONSTEXPR_OR_CONST ULONG_ WT_EXECUTEINUITHREAD_ = 0x00000002;
  64. #else
  65. BOOST_CONSTEXPR_OR_CONST ULONG_ WT_EXECUTEINUITHREAD_ = WT_EXECUTEINUITHREAD;
  66. #endif
  67. BOOST_CONSTEXPR_OR_CONST ULONG_ WT_EXECUTEINWAITTHREAD_ = WT_EXECUTEINWAITTHREAD;
  68. BOOST_CONSTEXPR_OR_CONST ULONG_ WT_EXECUTEONLYONCE_ = WT_EXECUTEONLYONCE;
  69. BOOST_CONSTEXPR_OR_CONST ULONG_ WT_EXECUTEINTIMERTHREAD_ = WT_EXECUTEINTIMERTHREAD;
  70. BOOST_CONSTEXPR_OR_CONST ULONG_ WT_EXECUTELONGFUNCTION_ = WT_EXECUTELONGFUNCTION;
  71. #if defined( BOOST_WINAPI_IS_MINGW )
  72. BOOST_CONSTEXPR_OR_CONST ULONG_ WT_EXECUTEINPERSISTENTIOTHREAD_ = 0x00000040;
  73. #else
  74. BOOST_CONSTEXPR_OR_CONST ULONG_ WT_EXECUTEINPERSISTENTIOTHREAD_ = WT_EXECUTEINPERSISTENTIOTHREAD;
  75. #endif
  76. BOOST_CONSTEXPR_OR_CONST ULONG_ WT_EXECUTEINPERSISTENTTHREAD_ = WT_EXECUTEINPERSISTENTTHREAD;
  77. BOOST_CONSTEXPR_OR_CONST ULONG_ WT_TRANSFER_IMPERSONATION_ = WT_TRANSFER_IMPERSONATION;
  78. #else // defined( BOOST_USE_WINDOWS_H )
  79. BOOST_CONSTEXPR_OR_CONST ULONG_ WT_EXECUTEDEFAULT_ = 0x00000000;
  80. BOOST_CONSTEXPR_OR_CONST ULONG_ WT_EXECUTEINIOTHREAD_ = 0x00000001;
  81. BOOST_CONSTEXPR_OR_CONST ULONG_ WT_EXECUTEINUITHREAD_ = 0x00000002;
  82. BOOST_CONSTEXPR_OR_CONST ULONG_ WT_EXECUTEINWAITTHREAD_ = 0x00000004;
  83. BOOST_CONSTEXPR_OR_CONST ULONG_ WT_EXECUTEONLYONCE_ = 0x00000008;
  84. BOOST_CONSTEXPR_OR_CONST ULONG_ WT_EXECUTEINTIMERTHREAD_ = 0x00000020;
  85. BOOST_CONSTEXPR_OR_CONST ULONG_ WT_EXECUTELONGFUNCTION_ = 0x00000010;
  86. BOOST_CONSTEXPR_OR_CONST ULONG_ WT_EXECUTEINPERSISTENTIOTHREAD_ = 0x00000040;
  87. BOOST_CONSTEXPR_OR_CONST ULONG_ WT_EXECUTEINPERSISTENTTHREAD_ = 0x00000080;
  88. BOOST_CONSTEXPR_OR_CONST ULONG_ WT_TRANSFER_IMPERSONATION_ = 0x00000100;
  89. #endif // defined( BOOST_USE_WINDOWS_H )
  90. BOOST_FORCEINLINE BOOST_CONSTEXPR ULONG_ wt_set_max_threadpool_threads(ULONG_ flags, ULONG_ limit) BOOST_NOEXCEPT
  91. {
  92. // Note: We don't use WT_SET_MAX_THREADPOOL_THREADS here because the way it's defined
  93. // the function no longer meets C++11 constexpr requirements.
  94. return flags | (limit << 16);
  95. }
  96. BOOST_CONSTEXPR_OR_CONST ULONG_ wt_execute_default = WT_EXECUTEDEFAULT_;
  97. BOOST_CONSTEXPR_OR_CONST ULONG_ wt_execute_in_io_thread = WT_EXECUTEINIOTHREAD_;
  98. BOOST_CONSTEXPR_OR_CONST ULONG_ wt_execute_in_ui_thread = WT_EXECUTEINUITHREAD_;
  99. BOOST_CONSTEXPR_OR_CONST ULONG_ wt_execute_in_wait_thread = WT_EXECUTEINWAITTHREAD_;
  100. BOOST_CONSTEXPR_OR_CONST ULONG_ wt_execute_only_once = WT_EXECUTEONLYONCE_;
  101. BOOST_CONSTEXPR_OR_CONST ULONG_ wt_execute_in_timer_thread = WT_EXECUTEINTIMERTHREAD_;
  102. BOOST_CONSTEXPR_OR_CONST ULONG_ wt_execute_long_function = WT_EXECUTELONGFUNCTION_;
  103. BOOST_CONSTEXPR_OR_CONST ULONG_ wt_execute_in_persistent_io_thread = WT_EXECUTEINPERSISTENTIOTHREAD_;
  104. BOOST_CONSTEXPR_OR_CONST ULONG_ wt_execute_in_persistent_thread = WT_EXECUTEINPERSISTENTTHREAD_;
  105. BOOST_CONSTEXPR_OR_CONST ULONG_ wt_transfer_impersonation = WT_TRANSFER_IMPERSONATION_;
  106. }
  107. }
  108. #include <boost/winapi/detail/footer.hpp>
  109. #endif // BOOST_USE_WINAPI_VERSION >= BOOST_WINAPI_VERSION_WIN2K
  110. #endif // BOOST_WINAPI_THREAD_POOL_HPP_INCLUDED_