xtd 0.2.0
Loading...
Searching...
No Matches
wait_handle.hpp
Go to the documentation of this file.
1
4#pragma once
5
6#include "timeout.hpp"
7#include "../abstract.hpp"
8#include "../as.hpp"
9#include "../size_object.hpp"
10#include "../time_span.hpp"
11#include "../types.hpp"
12#include <limits>
13#include <vector>
14
16namespace xtd {
18 namespace threading {
21 class thread;
23
52 class core_export_ wait_handle abstract_ {
53 friend class registered_wait_handle;
54 friend class thread;
55 public:
57
63 static const intptr invalid_handle;
64
69
71
74 wait_handle() = default;
76
80
82
86 virtual auto handle() const noexcept -> intptr = 0;
89 virtual auto handle(intptr value) -> void = 0;
91
93
97 virtual auto close() -> void;
98
103 virtual auto wait_one() -> bool;
104
111 virtual auto wait_one(int32 milliseconds_timeout) -> bool;
112
119 virtual auto wait_one(const time_span& timeout) -> bool;
121
123
132 static auto signal_and_wait(wait_handle& to_signal, wait_handle& to_wait) -> bool;
133
142 static auto signal_and_wait(wait_handle& to_signal, wait_handle& to_wait, int32 milliseconds_timeout) -> bool;
143
152 static auto signal_and_wait(wait_handle& to_signal, wait_handle& to_wait, const time_span& timeout) -> bool;
153
160 template<class collection_t>
161 static auto wait_all(const collection_t& wait_handles) -> bool {return wait_all(wait_handles, timeout::infinite);}
162
171 template<class collection_t>
172 static auto wait_all(const collection_t& wait_handles, int32 milliseconds_timeout) -> bool {
173 auto wait_handle_pointers = std::vector<wait_handle*> {};
174 for (auto& item : wait_handles)
175 wait_handle_pointers.push_back(const_cast<wait_handle*>(as<wait_handle>(&item)));
176 return wait_all(array<wait_handle*> {wait_handle_pointers}, milliseconds_timeout);
177 }
178
187 template<class collection_t>
188 static auto wait_all(const collection_t& wait_handles, const time_span& timeout) -> bool {return wait_all(wait_handles, as<int32>(timeout.total_milliseconds_duration().count()));}
189
197 template<class collection_t>
198 static auto wait_any(const collection_t& wait_handles) -> xtd::size {return wait_any(wait_handles, timeout::infinite);}
199
208 template<class collection_t>
209 static auto wait_any(const collection_t& wait_handles, int32 milliseconds_timeout) -> xtd::size {
210 auto wait_handle_pointers = std::vector<wait_handle*> {};
211 for (auto& item : wait_handles)
212 wait_handle_pointers.push_back(const_cast<wait_handle*>(as<wait_handle>(&item)));
213 return wait_any(xtd::array<wait_handle*> {wait_handle_pointers}, milliseconds_timeout);
214 }
215
224 template<class collection_t>
225 static auto wait_any(const collection_t& wait_handles, const time_span& timeout) -> xtd::size {return wait_any(wait_handles, as<int32>(timeout.total_milliseconds_duration().count()));}
227
229 template<class ...items_t>
230 static auto wait_all(items_t... items) -> bool {return wait_all(timeout::infinite, items...);}
231 template<class ...items_t>
232 static auto wait_all(const time_span& timeout, items_t... items) -> bool {return wait_all(as<int32>(timeout.total_milliseconds()), items...);}
233 template<class ...items_t>
234 static auto wait_all(int32 milliseconds_timeout, items_t... items) -> bool {
235 auto wait_handle_pointers = std::vector<wait_handle*> {};
236 fill_wait_handle_pointers(wait_handle_pointers, items...);
237 return wait_all(xtd::array<wait_handle*> {wait_handle_pointers}, milliseconds_timeout);
238 }
239 template<class item_t>
240 static auto wait_all(const std::initializer_list<item_t>& wait_handles) -> bool {return wait_all(wait_handles, timeout::infinite);}
241 template<class item_t>
242 static auto wait_all(const std::initializer_list<item_t>& wait_handles, int32 milliseconds_timeout) -> bool {
243 auto wait_handle_pointers = std::vector<wait_handle*> {};
244 for (auto& item : wait_handles)
245 wait_handle_pointers.push_back(const_cast<wait_handle*>(as<wait_handle>(&item)));
246 return wait_all(xtd::array<wait_handle*> {wait_handle_pointers}, milliseconds_timeout);
247 }
248 template<class item_t>
249 static auto wait_all(const std::initializer_list<item_t>& wait_handles, const time_span& timeout) -> bool {return wait_all(wait_handles, as<int32>(timeout.total_milliseconds_duration().count()));}
250 static auto wait_all(const std::initializer_list<xtd::sptr<wait_handle>>& wait_handles) -> bool;
251 static auto wait_all(const std::initializer_list<xtd::sptr<wait_handle>>& wait_handles, int32 milliseconds_timeout) -> bool;
252 static auto wait_all(const std::initializer_list<xtd::sptr<wait_handle>>& wait_handles, const time_span& timeout) -> bool;
253 static auto wait_all(const std::initializer_list<xtd::uptr<wait_handle>>& wait_handles) -> bool;
254 static auto wait_all(const std::initializer_list<xtd::uptr<wait_handle>>& wait_handles, int32 milliseconds_timeout) -> bool;
255 static auto wait_all(const std::initializer_list<xtd::uptr<wait_handle>>& wait_handles, const time_span& timeout) -> bool;
256 static auto wait_all(const xtd::array<xtd::sptr<wait_handle>>& wait_handles) -> bool;
257 static auto wait_all(const xtd::array<xtd::sptr<wait_handle>>& wait_handles, int32 milliseconds_timeout) -> bool;
258 static auto wait_all(const xtd::array<xtd::sptr<wait_handle>>& wait_handles, const time_span& timeout) -> bool;
259 static auto wait_all(const xtd::array<xtd::uptr<wait_handle>>& wait_handles) -> bool;
260 static auto wait_all(const xtd::array<xtd::uptr<wait_handle>>& wait_handles, int32 milliseconds_timeout) -> bool;
261 static auto wait_all(const xtd::array<xtd::uptr<wait_handle>>& wait_handles, const time_span& timeout) -> bool;
262 static auto wait_all(const xtd::array<wait_handle*>& wait_handles, int32 milliseconds_timeout) -> bool;
263
264 template<class ...items_t>
265 static auto wait_any(items_t... items) -> xtd::size {return wait_any(timeout::infinite, items...);}
266 template<class ...items_t>
267 static auto wait_any(const time_span& timeout, items_t... items) -> xtd::size {return wait_any(as<int32>(timeout.total_milliseconds()), items...);}
268 template<class ...items_t>
269 static auto wait_any(int32 milliseconds_timeout, items_t... items) -> xtd::size {
270 auto wait_handle_pointers = std::vector<wait_handle*> {};
271 fill_wait_handle_pointers(wait_handle_pointers, items...);
272 return wait_any(xtd::array<wait_handle*> {wait_handle_pointers}, milliseconds_timeout);
273 }
274 template<class item_t>
275 static auto wait_any(const std::initializer_list<item_t>& wait_handles) -> xtd::size {return wait_any(wait_handles, timeout::infinite);}
276 template<class item_t>
277 static auto wait_any(const std::initializer_list<item_t>& wait_handles, int32 milliseconds_timeout) -> xtd::size {
278 auto wait_handle_pointers = std::vector<wait_handle*> {};
279 for (auto& item : wait_handles)
280 wait_handle_pointers.push_back(const_cast<wait_handle*>(as<wait_handle>(&item)));
281 return wait_any(xtd::array<wait_handle*> {wait_handle_pointers}, milliseconds_timeout);
282 }
283 template<class item_t>
284 static auto wait_any(const std::initializer_list<item_t>& wait_handles, const time_span& timeout) -> xtd::size {return wait_any(wait_handles, as<int32>(timeout.total_milliseconds_duration().count()));}
285 static auto wait_any(const std::initializer_list<xtd::sptr<wait_handle>>& wait_handles) -> xtd::size;
286 static auto wait_any(const std::initializer_list<xtd::sptr<wait_handle>>& wait_handles, int32 milliseconds_timeout) -> xtd::size;
287 static auto wait_any(const std::initializer_list<xtd::sptr<wait_handle>>& wait_handles, const time_span& timeout) -> xtd::size;
288 static auto wait_any(const std::initializer_list<xtd::uptr<wait_handle>>& wait_handles) -> xtd::size;
289 static auto wait_any(const std::initializer_list<xtd::uptr<wait_handle>>& wait_handles, int32 milliseconds_timeout) -> xtd::size;
290 static auto wait_any(const std::initializer_list<xtd::uptr<wait_handle>>& wait_handles, const time_span& timeout) -> xtd::size;
291 static auto wait_any(const xtd::array<xtd::sptr<wait_handle>>& wait_handles) -> xtd::size;
292 static auto wait_any(const xtd::array<xtd::sptr<wait_handle>>& wait_handles, int32 milliseconds_timeout) -> xtd::size;
293 static auto wait_any(const xtd::array<xtd::sptr<wait_handle>>& wait_handles, const time_span& timeout) -> xtd::size;
294 static auto wait_any(const xtd::array<xtd::uptr<wait_handle>>& wait_handles) -> xtd::size;
295 static auto wait_any(const xtd::array<xtd::uptr<wait_handle>>& wait_handles, int32 milliseconds_timeout) -> xtd::size;
296 static auto wait_any(const xtd::array<xtd::uptr<wait_handle>>& wait_handles, const time_span& timeout) -> xtd::size;
297 static auto wait_any(const xtd::array<wait_handle*>& wait_handles, int32 milliseconds_timeout) -> xtd::size;
299
300 protected:
302
307 virtual auto signal() -> bool = 0;
308
315 virtual auto wait(int32 milliseconds_timeout) -> bool = 0;
317
318 private:
319 template<class item_t, class ...items_t>
320 static auto fill_wait_handle_pointers(std::vector<wait_handle*>& wait_handle_pointers, item_t& first, items_t& ... rest) -> void {
321 wait_handle_pointers.push_back(const_cast<wait_handle*>(as<wait_handle>(&first)));
322 fill_wait_handle_pointers(wait_handle_pointers, rest...);
323 }
324 template<class item_t>
325 static auto fill_wait_handle_pointers(std::vector<wait_handle*>& wait_handle_pointers, item_t& item) -> void {
326 wait_handle_pointers.push_back(const_cast<wait_handle*>(as<wait_handle>(&item)));
327 }
328 };
329 }
330}
Contains abstract_ keyword.
Contains xtd::as method.
Provides methods for creating, manipulating, searching, and sorting arrays, thereby serving as the ba...
Definition array.hpp:64
static constexpr size_t max_value
Definition box_integer.hpp:71
A synchronization primitive that can also be used for interprocess synchronization.
Definition registered_wait_handle.hpp:29
Creates and controls a thread, sets its priority, and gets its status.
Definition thread.hpp:49
Contains a constant used to specify an infinite amount of time. This class cannot be inherited.
Definition timeout.hpp:33
static constexpr int32 infinite
A constant used to specify an infinite waiting period. This field is constant.
Definition timeout.hpp:41
Encapsulates operating system specific objects that wait for exclusive access to shared resources.
Definition wait_handle.hpp:52
static auto wait_all(const collection_t &wait_handles) -> bool
Waits for all the elements in the specified collection to receive a signal.
Definition wait_handle.hpp:161
static const intptr invalid_handle
Represents an invalid native operating system handle. This field is read-only.
Definition wait_handle.hpp:63
static constexpr xtd::size wait_timeout
Indicates that a xtd::threading::wait_handle::wait_any operation timed out before any of the wait han...
Definition wait_handle.hpp:67
static auto signal_and_wait(wait_handle &to_signal, wait_handle &to_wait) -> bool
Signals one xtd::threading::wait_handle and waits on another.
static auto wait_any(const collection_t &wait_handles, const time_span &timeout) -> xtd::size
Waits for any of the elements in the specified collection to receive a signal, using a xtd::time_span...
Definition wait_handle.hpp:225
virtual auto handle() const noexcept -> intptr=0
Gets the native operating system handle.
virtual auto wait_one() -> bool
Blocks the current thread until the current xtd::threading::wait_handle receives a signal.
static auto wait_all(const collection_t &wait_handles, const time_span &timeout) -> bool
Waits for all the elements in the specified collection to receive a signal, using a xtd::time_span va...
Definition wait_handle.hpp:188
virtual auto close() -> void
Releases all resources held by the current xtd::threading::wait_handle.
wait_handle()=default
Initializes a new instance of the xtd::threading::wait_handle class.
virtual auto wait(int32 milliseconds_timeout) -> bool=0
wait ownership of the specified mutex object.
static auto wait_all(const collection_t &wait_handles, int32 milliseconds_timeout) -> bool
Waits for all the elements in the specified collection to receive a signal, using an int32 value to m...
Definition wait_handle.hpp:172
static auto wait_any(const collection_t &wait_handles, int32 milliseconds_timeout) -> xtd::size
Waits for any of the elements in the specified collection to receive a signal, using a 32-bit signed ...
Definition wait_handle.hpp:209
virtual auto signal() -> bool=0
Releases ownership of the specified wait_handle object.
static auto wait_any(const collection_t &wait_handles) -> xtd::size
Waits for any of the elements in the specified collection to receive a signal.
Definition wait_handle.hpp:198
Represents a time interval.
Definition time_span.hpp:29
#define core_export_
Define shared library export.
Definition core_export.hpp:13
size_t size
Represents a size of any object in bytes.
Definition size.hpp:23
xtd::shared_ptr_object< type_t > sptr
The xtd::sptr object is a shared pointer.
Definition sptr.hpp:25
std::intmax_t intptr
Represent a pointer or a handle.
Definition intptr.hpp:23
xtd::unique_ptr_object< type_t > uptr
The xtd::uptr object is a unique pointer.
Definition uptr.hpp:25
std::int32_t int32
Represents a 32-bit signed integer.
Definition int32.hpp:23
auto as(any_object &o) -> type_t
Casts a type into another type.
Definition __as_any_object.hpp:60
The xtd::threading namespace provides classes and interfaces that enable multithreaded programming....
Definition abandoned_mutex_exception.hpp:10
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition abstract_object.hpp:8
read_only_span< type_t, count > first() const
Obtains a subspan consisting of the first count elements of the sequence.
Definition read_only_span.hpp:282
Contains xtd::size_object alias.
Contains xtd::time_span class.
Contains xtd::threading::timeout class.
Contains xtd fundamental types.