8#if __has_include("defs.h")
12#include "safe_winsock.h"
41 virtual DWORD
wait (DWORD limit_msec);
44 virtual DWORD
wait (std::chrono::milliseconds limit);
49 virtual DWORD
wait_msg (DWORD limit_msec = INFINITE, DWORD mask = QS_ALLINPUT);
60 virtual const std::string&
name ()
const
68 virtual void name (
const std::string& nam);
74 std::atomic_int lives;
88 assert (hl && hl->handle_);
89 WaitForSingleObject (hl->handle_, INFINITE);
99 assert (hl && hl->handle_);
100 return WaitForSingleObject (hl->handle_, limit_msec);
110 assert (hl && hl->handle_);
111 auto limit_msec = limit.count ();
112 assert (0 < limit_msec && limit_msec < INFINITE);
113 return WaitForSingleObject (hl->handle_, (DWORD)limit_msec);
120 assert (hl && hl->handle_);
121 return WaitForSingleObjectEx (hl->handle_, limit_msec, TRUE);
139 return MsgWaitForMultipleObjects (1, &hl->handle_, FALSE, limit_msec, mask);
143inline syncbase::operator bool ()
145 return is_signaled ();
155 return (WaitForSingleObject (hl->handle_, 0) == WAIT_OBJECT_0);
171DWORD
wait_all (
const T* objs,
int count, DWORD msec = INFINITE)
173 assert (count < MAXIMUM_WAIT_OBJECTS);
174 HANDLE harr[MAXIMUM_WAIT_OBJECTS];
175 for (
int i = 0; i < count; i++)
176 harr[i] = objs[i]->handle ();
178 DWORD result = WaitForMultipleObjects (count, harr,
true, msec);
194DWORD
wait_all (std::initializer_list<const T*> objs, DWORD msec = INFINITE)
196 assert (objs.size () < MAXIMUM_WAIT_OBJECTS);
197 HANDLE harr[MAXIMUM_WAIT_OBJECTS];
200 harr[i++] = p->handle ();
202 DWORD result = WaitForMultipleObjects ((DWORD)objs.size (), harr,
true, msec);
218DWORD
wait_all (std::initializer_list<const T*> objs, std::chrono::milliseconds limit)
220 assert (objs.size () < MAXIMUM_WAIT_OBJECTS);
221 HANDLE harr[MAXIMUM_WAIT_OBJECTS];
224 harr[i++] = p->handle ();
226 DWORD msec = (DWORD)limit.count ();
227 DWORD result = WaitForMultipleObjects ((DWORD)objs.size (), harr,
true, msec);
244DWORD
wait_any (
const T* objs,
int count, DWORD msec = INFINITE)
246 assert (count < MAXIMUM_WAIT_OBJECTS);
247 HANDLE harr[MAXIMUM_WAIT_OBJECTS];
248 for (
int i = 0; i < count; i++)
249 harr[i] = objs[i].handle ();
251 DWORD result = WaitForMultipleObjects (count, harr,
false, msec);
267DWORD
wait_any (std::initializer_list<const T*> objs, DWORD msec = INFINITE)
269 assert (objs.size () < MAXIMUM_WAIT_OBJECTS);
270 HANDLE harr[MAXIMUM_WAIT_OBJECTS];
273 harr[i++] = p->handle ();
275 DWORD result = WaitForMultipleObjects ((DWORD)objs.size (), harr,
false, msec);
291DWORD
wait_any (std::initializer_list<const T*> objs, std::chrono::milliseconds timeout)
293 assert (objs.size () < MAXIMUM_WAIT_OBJECTS);
294 HANDLE harr[MAXIMUM_WAIT_OBJECTS];
297 harr[i++] = p->handle ();
298 DWORD msec = (DWORD)timeout.count ();
299 DWORD result = WaitForMultipleObjects ((DWORD)objs.size (), harr,
false, msec);
318DWORD
wait_msg (
const T* objs,
int count,
bool all =
true, DWORD msec = INFINITE,
319 DWORD mask = QS_ALLINPUT)
321 assert (count < MAXIMUM_WAIT_OBJECTS);
322 HANDLE harr[MAXIMUM_WAIT_OBJECTS];
323 for (
int i = 0; i < count; i++)
324 harr[i] = objs[i]->handle ();
326 DWORD result = MsgWaitForMultipleObjects (count, harr, all, msec, mask);
344DWORD
wait_msg (std::initializer_list<const T*> objs,
bool all =
true, DWORD msec = INFINITE,
345 DWORD mask = QS_ALLINPUT)
347 assert (objs.size () < MAXIMUM_WAIT_OBJECTS);
348 HANDLE harr[MAXIMUM_WAIT_OBJECTS];
351 harr[i++] = p->handle ();
353 DWORD result = MsgWaitForMultipleObjects ((DWORD)objs.size (), harr, all, msec, mask);
Base class for all named synchronization objects.
Definition syncbase.h:27
HANDLE handle() const
Return OS handle of this object.
Definition syncbase.h:54
void set_handle(HANDLE h)
Change object's handle. Closes the previous one.
Definition syncbase.cpp:125
syncbase()
Default constructor.
Definition syncbase.cpp:37
virtual void wait()
Wait for object to become signaled.
Definition syncbase.h:86
syncbase & operator=(const syncbase &rhs)
Assignment operator.
Definition syncbase.cpp:81
virtual DWORD wait_alertable(DWORD limit_msec=INFINITE)
Definition syncbase.h:118
int operator==(const syncbase &rhs) const
Equality operator.
Definition syncbase.cpp:119
virtual const std::string & name() const
Return object's name.
Definition syncbase.h:60
virtual DWORD wait_msg(DWORD limit_msec=INFINITE, DWORD mask=QS_ALLINPUT)
Wait for object to become signaled or a message to be queued.
Definition syncbase.h:137
virtual ~syncbase()
Destructor.
Definition syncbase.cpp:69
virtual bool is_signaled()
Try to wait on the object.
Definition syncbase.h:153
DWORD wait_any(const T *objs, int count, DWORD msec=INFINITE)
Wait for multiple objects until any of them becomes signaled.
Definition syncbase.h:244
DWORD wait_all(const T *objs, int count, DWORD msec=INFINITE)
Wait for multiple objects until all become signaled.
Definition syncbase.h:171
DWORD wait_msg(const T *objs, int count, bool all=true, DWORD msec=INFINITE, DWORD mask=QS_ALLINPUT)
Wait for multiple objects or a message to be queued.
Definition syncbase.h:318