7#include "../abstract.h"
9#include "../size_object.h"
10#include "../time_span.h"
20 class registered_wait_handle;
67 static constexpr size_t wait_timeout = size_object::max_value;
89 virtual
void handle(
intptr value) = 0;
103 virtual
bool wait_one();
111 virtual
bool wait_one(
int32 milliseconds_timeout);
160 template<typename collection_t>
161 static
bool wait_all(const collection_t& wait_handles) {
return wait_all(wait_handles, timeout::infinite);}
171 template<
typename collection_t>
172 static bool wait_all(
const collection_t& wait_handles,
int32 milliseconds_timeout) {
173 std::vector<wait_handle*> wait_handle_pointers;
174 for (
auto& item : wait_handles)
175 wait_handle_pointers.push_back(
const_cast<wait_handle*
>(as<wait_handle>(&item)));
176 return wait_all(wait_handle_pointers, milliseconds_timeout);
187 template<
typename collection_t>
197 template<
typename collection_t>
198 static size_t wait_any(
const collection_t& wait_handles) {
return wait_any(wait_handles, timeout::infinite);}
208 template<
typename collection_t>
209 static size_t wait_any(
const collection_t& wait_handles,
int32 milliseconds_timeout) {
210 std::vector<wait_handle*> wait_handle_pointers;
211 for (
auto& item : wait_handles)
212 wait_handle_pointers.push_back(
const_cast<wait_handle*
>(as<wait_handle>(&item)));
213 return wait_any(wait_handle_pointers, milliseconds_timeout);
224 template<
typename collection_t>
229 template <
typename... items_t>
230 static size_t wait_all(items_t... items) {
return wait_all(timeout::infinite, items...);}
231 template <
typename... items_t>
232 static size_t wait_all(
const time_span& timeout, items_t... items) {
return wait_all(as<int32>(timeout.
total_milliseconds()), items...);}
233 template <
typename... items_t>
234 static size_t wait_all(int32 milliseconds_timeout, items_t... items) {
235 std::vector<wait_handle*> wait_handle_pointers;
236 fill_wait_handle_pointers(wait_handle_pointers, items...);
237 return wait_all(wait_handle_pointers, milliseconds_timeout);
239 template<
typename item_t>
240 static bool wait_all(
const std::initializer_list<item_t>& wait_handles) {
return wait_all(wait_handles, timeout::infinite);}
241 template<
typename item_t>
242 static bool wait_all(
const std::initializer_list<item_t>& wait_handles, int32 milliseconds_timeout) {
243 std::vector<wait_handle*> wait_handle_pointers;
244 for (
auto& item : wait_handles)
245 wait_handle_pointers.push_back(const_cast<wait_handle*>(
as<wait_handle>(&item)));
246 return wait_all(wait_handle_pointers, milliseconds_timeout);
248 template<
typename item_t>
249 static bool wait_all(
const std::initializer_list<item_t>& wait_handles,
const time_span& timeout) {
return wait_all(wait_handles, as<int32>(timeout.total_milliseconds_duration().count()));}
251 static bool wait_all(
const std::initializer_list<
xtd::sptr<wait_handle>>& wait_handles, int32 milliseconds_timeout);
252 static bool wait_all(
const std::initializer_list<
xtd::sptr<wait_handle>>& wait_handles,
const time_span& timeout);
254 static bool wait_all(
const std::initializer_list<
xtd::uptr<wait_handle>>& wait_handles, int32 milliseconds_timeout);
255 static bool wait_all(
const std::initializer_list<
xtd::uptr<wait_handle>>& wait_handles,
const time_span& timeout);
257 static bool wait_all(
const std::vector<
xtd::sptr<wait_handle>>& wait_handles, int32 milliseconds_timeout);
260 static bool wait_all(
const std::vector<
xtd::uptr<wait_handle>>& wait_handles, int32 milliseconds_timeout);
262 static bool wait_all(
const std::vector<wait_handle*>& wait_handles, int32 milliseconds_timeout);
264 template <
typename... items_t>
265 static size_t wait_any(items_t... items) {
return wait_any(timeout::infinite, items...);}
266 template <
typename... items_t>
267 static size_t wait_any(
const time_span& timeout, items_t... items) {
return wait_any(as<int32>(timeout.total_milliseconds()), items...);}
268 template <
typename... items_t>
269 static size_t wait_any(int32 milliseconds_timeout, items_t... items) {
270 std::vector<wait_handle*> wait_handle_pointers;
271 fill_wait_handle_pointers(wait_handle_pointers, items...);
272 return wait_any(wait_handle_pointers, milliseconds_timeout);
274 template<
typename item_t>
275 static size_t wait_any(
const std::initializer_list<item_t>& wait_handles) {
return wait_any(wait_handles, timeout::infinite);}
276 template<
typename item_t>
277 static size_t wait_any(
const std::initializer_list<item_t>& wait_handles, int32 milliseconds_timeout) {
278 std::vector<wait_handle*> wait_handle_pointers;
279 for (
auto& item : wait_handles)
280 wait_handle_pointers.push_back(const_cast<wait_handle*>(
as<wait_handle>(&item)));
281 return wait_any(wait_handle_pointers, milliseconds_timeout);
283 template<
typename item_t>
284 static size_t wait_any(
const std::initializer_list<item_t>& wait_handles,
const time_span& timeout) {
return wait_any(wait_handles, as<int32>(timeout.total_milliseconds_duration().count()));}
286 static size_t wait_any(
const std::initializer_list<
xtd::sptr<wait_handle>>& wait_handles, int32 milliseconds_timeout);
287 static size_t wait_any(
const std::initializer_list<
xtd::sptr<wait_handle>>& wait_handles,
const time_span& timeout);
289 static size_t wait_any(
const std::initializer_list<
xtd::uptr<wait_handle>>& wait_handles, int32 milliseconds_timeout);
290 static size_t wait_any(
const std::initializer_list<
xtd::uptr<wait_handle>>& wait_handles,
const time_span& timeout);
292 static size_t wait_any(
const std::vector<
xtd::sptr<wait_handle>>& wait_handles, int32 milliseconds_timeout);
293 static size_t wait_any(
const std::vector<
xtd::sptr<wait_handle>>& wait_handles,
const time_span& timeout);
295 static size_t wait_any(
const std::vector<
xtd::uptr<wait_handle>>& wait_handles, int32 milliseconds_timeout);
296 static size_t wait_any(
const std::vector<
xtd::uptr<wait_handle>>& wait_handles,
const time_span& timeout);
297 static size_t wait_any(
const std::vector<wait_handle*>& wait_handles, int32 milliseconds_timeout);
319 template <
typename item_t,
typename... items_t>
320 static void fill_wait_handle_pointers(std::vector<wait_handle*>& wait_handle_pointers, item_t& first, items_t&... rest) {
321 wait_handle_pointers.push_back(
const_cast<wait_handle*
>(as<wait_handle>(&first)));
322 fill_wait_handle_pointers(wait_handle_pointers, rest...);
324 template <
typename item_t>
325 static void fill_wait_handle_pointers(std::vector<wait_handle*>& wait_handle_pointers, item_t& item) {
326 wait_handle_pointers.push_back(
const_cast<wait_handle*
>(as<wait_handle>(&item)));
A synchronization primitive that can also be used for interprocess synchronization.
Definition registered_wait_handle.h:29
Creates and controls a thread, sets its priority, and gets its status.
Definition thread.h:43
Contains a constant used to specify an infinite amount of time. This class cannot be inherited.
Definition timeout.h:33
Encapsulates operating system specific objects that wait for exclusive access to shared resources.
Definition wait_handle.h:52
static const intptr invalid_handle
Represents an invalid native operating system handle. This field is read-only.
Definition wait_handle.h:63
static bool wait_all(const collection_t &wait_handles)
Waits for all the elements in the specified collection to receive a signal.
Definition wait_handle.h:161
static size_t wait_any(const collection_t &wait_handles, int32 milliseconds_timeout)
Waits for any of the elements in the specified collection to receive a signal, using a 32-bit signed ...
Definition wait_handle.h:209
wait_handle()=default
Initializes a new instance of the xtd::threading::wait_handle class.
static bool wait_all(const collection_t &wait_handles, int32 milliseconds_timeout)
Waits for all the elements in the specified collection to receive a signal, using an int32 value to m...
Definition wait_handle.h:172
virtual bool wait(int32 milliseconds_timeout)=0
wait ownership of the specified mutex object.
virtual intptr handle() const noexcept=0
Gets the native operating system handle.
virtual bool signal()=0
Releases ownership of the specified wait_handle object.
static bool wait_all(const collection_t &wait_handles, const time_span &timeout)
Waits for all the elements in the specified collection to receive a signal, using a xtd::time_span va...
Definition wait_handle.h:188
static size_t wait_any(const collection_t &wait_handles)
Waits for any of the elements in the specified collection to receive a signal.
Definition wait_handle.h:198
static size_t wait_any(const collection_t &wait_handles, const time_span &timeout)
Waits for any of the elements in the specified collection to receive a signal, using a xtd::time_span...
Definition wait_handle.h:225
#define abstract_
This keyword is used to represents an abstract class.
Definition abstract.h:25
#define core_export_
Define shared library export.
Definition core_export.h:13
int32_t int32
Represents a 32-bit signed integer.
Definition int32.h:23
std::unique_ptr< type_t > uptr
The xtd::uptr object is a unique pointer.
Definition uptr.h:25
intmax_t intptr
Represent a pointer or a handle.
Definition intptr.h:23
std::shared_ptr< type_t > sptr
The xtd::sptr object is a shared pointer.
Definition sptr.h:25
type_t as(any_object &o)
Casts a type into another type.
Definition __as_any_object.h:57
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.h:10
Represents a time interval.
Definition time_span.h:29
double total_milliseconds() const noexcept
Gets the value of the current xtd::time_span structure expressed in whole and fractional milliseconds...
Contains xtd::threading::timeout class.