thread_pool.hpp 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. // thread_pool.hpp --------------------------------------------------------------//
  2. // Copyright 2013 Andrey Semashev
  3. // Distributed under the Boost Software License, Version 1.0.
  4. // See http://www.boost.org/LICENSE_1_0.txt
  5. #ifndef BOOST_DETAIL_WINAPI_THREAD_POOL_HPP
  6. #define BOOST_DETAIL_WINAPI_THREAD_POOL_HPP
  7. #include <boost/detail/winapi/config.hpp>
  8. #ifdef BOOST_HAS_PRAGMA_ONCE
  9. #pragma once
  10. #endif
  11. #if BOOST_USE_WINAPI_VERSION >= BOOST_WINAPI_VERSION_WIN2K
  12. #include <boost/detail/winapi/basic_types.hpp>
  13. #if !defined( BOOST_USE_WINDOWS_H )
  14. extern "C" {
  15. typedef boost::detail::winapi::VOID_ (NTAPI *WAITORTIMERCALLBACKFUNC)
  16. (boost::detail::winapi::PVOID_, boost::detail::winapi::BOOLEAN_);
  17. typedef WAITORTIMERCALLBACKFUNC WAITORTIMERCALLBACK;
  18. BOOST_SYMBOL_IMPORT boost::detail::winapi::BOOL_ WINAPI
  19. RegisterWaitForSingleObject(
  20. boost::detail::winapi::PHANDLE_ phNewWaitObject,
  21. boost::detail::winapi::HANDLE_ hObject,
  22. WAITORTIMERCALLBACK Callback,
  23. boost::detail::winapi::PVOID_ Context,
  24. boost::detail::winapi::ULONG_ dwMilliseconds,
  25. boost::detail::winapi::ULONG_ dwFlags);
  26. }
  27. #endif
  28. // MinGW is buggy - it is missing these function declarations for Win2000
  29. #if !defined( BOOST_USE_WINDOWS_H ) || (defined(BOOST_WINAPI_IS_MINGW) && BOOST_USE_WINAPI_VERSION < BOOST_WINAPI_VERSION_WINXP)
  30. extern "C" {
  31. BOOST_SYMBOL_IMPORT boost::detail::winapi::BOOL_ WINAPI
  32. UnregisterWait(boost::detail::winapi::HANDLE_ WaitHandle);
  33. BOOST_SYMBOL_IMPORT boost::detail::winapi::BOOL_ WINAPI
  34. UnregisterWaitEx(
  35. boost::detail::winapi::HANDLE_ WaitHandle,
  36. boost::detail::winapi::HANDLE_ CompletionEvent);
  37. }
  38. #endif
  39. namespace boost {
  40. namespace detail {
  41. namespace winapi {
  42. typedef ::WAITORTIMERCALLBACKFUNC WAITORTIMERCALLBACKFUNC_;
  43. typedef ::WAITORTIMERCALLBACK WAITORTIMERCALLBACK_;
  44. using ::RegisterWaitForSingleObject;
  45. using ::UnregisterWait;
  46. using ::UnregisterWaitEx;
  47. #if defined( BOOST_USE_WINDOWS_H )
  48. const ULONG_ WT_EXECUTEDEFAULT_ = WT_EXECUTEDEFAULT;
  49. const ULONG_ WT_EXECUTEINIOTHREAD_ = WT_EXECUTEINIOTHREAD;
  50. #if defined( BOOST_WINAPI_IS_MINGW )
  51. const ULONG_ WT_EXECUTEINUITHREAD_ = 0x00000002;
  52. #else
  53. const ULONG_ WT_EXECUTEINUITHREAD_ = WT_EXECUTEINUITHREAD;
  54. #endif
  55. const ULONG_ WT_EXECUTEINWAITTHREAD_ = WT_EXECUTEINWAITTHREAD;
  56. const ULONG_ WT_EXECUTEONLYONCE_ = WT_EXECUTEONLYONCE;
  57. const ULONG_ WT_EXECUTEINTIMERTHREAD_ = WT_EXECUTEINTIMERTHREAD;
  58. const ULONG_ WT_EXECUTELONGFUNCTION_ = WT_EXECUTELONGFUNCTION;
  59. #if defined( BOOST_WINAPI_IS_MINGW )
  60. const ULONG_ WT_EXECUTEINPERSISTENTIOTHREAD_ = 0x00000040;
  61. #else
  62. const ULONG_ WT_EXECUTEINPERSISTENTIOTHREAD_ = WT_EXECUTEINPERSISTENTIOTHREAD;
  63. #endif
  64. const ULONG_ WT_EXECUTEINPERSISTENTTHREAD_ = WT_EXECUTEINPERSISTENTTHREAD;
  65. const ULONG_ WT_TRANSFER_IMPERSONATION_ = WT_TRANSFER_IMPERSONATION;
  66. inline ULONG_ wt_set_max_threadpool_threads(ULONG_ flags, ULONG_ limit)
  67. {
  68. return WT_SET_MAX_THREADPOOL_THREADS(flags, limit);
  69. }
  70. #else // defined( BOOST_USE_WINDOWS_H )
  71. const ULONG_ WT_EXECUTEDEFAULT_ = 0x00000000;
  72. const ULONG_ WT_EXECUTEINIOTHREAD_ = 0x00000001;
  73. const ULONG_ WT_EXECUTEINUITHREAD_ = 0x00000002;
  74. const ULONG_ WT_EXECUTEINWAITTHREAD_ = 0x00000004;
  75. const ULONG_ WT_EXECUTEONLYONCE_ = 0x00000008;
  76. const ULONG_ WT_EXECUTEINTIMERTHREAD_ = 0x00000020;
  77. const ULONG_ WT_EXECUTELONGFUNCTION_ = 0x00000010;
  78. const ULONG_ WT_EXECUTEINPERSISTENTIOTHREAD_ = 0x00000040;
  79. const ULONG_ WT_EXECUTEINPERSISTENTTHREAD_ = 0x00000080;
  80. const ULONG_ WT_TRANSFER_IMPERSONATION_ = 0x00000100;
  81. inline ULONG_ wt_set_max_threadpool_threads(ULONG_ flags, ULONG_ limit)
  82. {
  83. return flags | (limit << 16);
  84. }
  85. #endif // defined( BOOST_USE_WINDOWS_H )
  86. const ULONG_ wt_execute_default = WT_EXECUTEDEFAULT_;
  87. const ULONG_ wt_execute_in_io_thread = WT_EXECUTEINIOTHREAD_;
  88. const ULONG_ wt_execute_in_ui_thread = WT_EXECUTEINUITHREAD_;
  89. const ULONG_ wt_execute_in_wait_thread = WT_EXECUTEINWAITTHREAD_;
  90. const ULONG_ wt_execute_only_once = WT_EXECUTEONLYONCE_;
  91. const ULONG_ wt_execute_in_timer_thread = WT_EXECUTEINTIMERTHREAD_;
  92. const ULONG_ wt_execute_long_function = WT_EXECUTELONGFUNCTION_;
  93. const ULONG_ wt_execute_in_persistent_io_thread = WT_EXECUTEINPERSISTENTIOTHREAD_;
  94. const ULONG_ wt_execute_in_persistent_thread = WT_EXECUTEINPERSISTENTTHREAD_;
  95. const ULONG_ wt_transfer_impersonation = WT_TRANSFER_IMPERSONATION_;
  96. }
  97. }
  98. }
  99. #endif // BOOST_USE_WINAPI_VERSION >= BOOST_WINAPI_VERSION_WIN2K
  100. #endif // BOOST_DETAIL_WINAPI_THREAD_POOL_HPP