10 #include "../core_export.h" 11 #include "../static.h" 12 #include "../time_span.h" 53 using asynchronous_io_thread_vector = std::vector<thread>;
57 template<
typename callback_t>
58 struct thread_item :
public object {
59 thread_item() =
default;
60 thread_item(
const callback_t& callback) : callback(callback) {}
61 thread_item(
const callback_t& callback,
std::any state) : callback(callback), state(state) {}
62 thread_item(
const callback_t& callback,
std::any state,
wait_handle& wait_object,
int32 milliseconds_timeout_interval,
bool execute_only_once) : callback(callback), state(state), wait_object(&wait_object), milliseconds_timeout_interval(milliseconds_timeout_interval), execute_only_once(execute_only_once) {}
67 int32 milliseconds_timeout_interval;
68 bool execute_only_once =
true;
69 bool unregistered =
false;
73 this->callback(state);
74 }
while (!execute_only_once);
78 using thread_pool_item = thread_item<wait_callback>;
79 using thread_pool_asynchronous_io_item = thread_item<wait_or_timer_callback>;
80 using thread_pool_item_collection = std::vector<thread_pool_item>;
81 using thread_pool_asynchronous_io_item_collection = std::vector<thread_pool_asynchronous_io_item>;
83 using thread_vector = std::vector<thread>;
100 static void get_available_threads(
size_t& worker_threads,
size_t& completion_port_threads);
108 static void get_max_threads(
size_t& worker_threads,
size_t& completion_port_threads);
113 static void get_min_threads(
size_t& worker_threads,
size_t& completion_port_threads);
120 static void join_all();
126 static bool join_all(
int32 milliseconds_timeout);
137 static bool queue_user_work_item(
const wait_callback& callback);
145 template <
typename callback_t>
146 static bool queue_user_work_item(callback_t callback) {
return queue_user_work_item(
wait_callback {callback});}
147 template <
typename callback_t>
148 static bool queue_user_work_item(callback_t callback,
std::any state) {
return queue_user_work_item(
wait_callback {callback}, state);}
189 template <
typename callback_t>
191 template <
typename callback_t>
193 template <
typename callback_t>
195 template <
typename callback_t>
203 static bool set_max_threads(
size_t worker_threads,
size_t completion_port_threads);
209 static bool set_min_threads(
size_t worker_threads,
size_t completion_port_threads);
214 static void asynchronous_io_run();
215 static void create_thread();
216 static void create_asynchronous_io_thread();
217 static static_data& get_static_data();
218 static void initialize_min_threads();
219 static void initialize_min_asynchronous_io_threads();
220 static bool join_all_threads(
int32 milliseconds_timeout);
221 static bool join_all_asynchronous_io_threads(
int32 milliseconds_timeout);
224 static size_t max_threads_;
225 static size_t max_asynchronous_io_threads_;
226 static size_t min_threads_;
227 static size_t min_asynchronous_io_threads_;
234 #define __XTD_CORE_INTERNAL__ 235 #include "../internal/__delegate.h" 236 #undef __XTD_CORE_INTERNAL__ 237 #define static_
This keyword is use to represent a static object. A static object can't be instantiated (constructors...
Definition: static.h:37
Contains xtd::threading::wait_callback exception.
The xtd namespace contains all fundamental classes to access Hardware, Os, System, and more.
Definition: system_report.h:17
Contains xtd::threading::wait_or_timer_callback exception.
delegate< void(std::any, bool)> wait_or_timer_callback
Represents a method to be called when a xtd::threading::wait_handle is signaled or times out...
Definition: wait_or_timer_callback.h:28
Contains xtd::threading::thread class.
Provides a pool of threads that can be used to execute tasks, post work items, process asynchronous I...
Definition: thread_pool.h:50
std::nullptr_t null
Represents a null pointer value.
delegate< void(std::any)> wait_callback
Represents a callback method to be executed by a thread pool thread.
Definition: wait_callback.h:28
Contains xtd::threading::semaphore exception.
A synchronization primitive that can also be used for interprocess synchronization.
Definition: registered_wait_handle.h:27
Contains xtd::threading::registered_wait_handle exception.
Indicates that all styles except allow_binary_specifier, allow_octal_specifier and allow_hex_specifie...
Creates and controls a thread, sets its priority, and gets its status.
Definition: thread.h:41
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes...
Definition: object.h:32
Represents a time interval.
Definition: time_span.h:26
int_least32_t int32
Represents a 32-bit signed integer.
Definition: types.h:129
Contains a constant used to specify an infinite amount of time. This class cannot be inherited...
Definition: timeout.h:31
int_least64_t int64
Represents a 64-bit signed integer.
Definition: types.h:140
uint_least32_t uint32
Represents a 32-bit unsigned integer.
Definition: types.h:239
Encapsulates operating system specific objects that wait for exclusive access to shared resources...
Definition: wait_handle.h:48