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