|
KanoopCommonQt 2.1.1
Kanoop foundational Qt utility library
|
|
#include <mutexevent.h>
Public Member Functions | |
| MutexEvent (bool wakeAllWaiters=false) | |
| Construct a MutexEvent. | |
| virtual | ~MutexEvent () |
| Virtual destructor. | |
| void | set () |
| Signal the event, waking one (or all) waiting thread(s). | |
| void | clear () |
| Reset the event to the unsignalled state. | |
| bool | wait (int msecs=0) |
| Block the calling thread until the event is set or the timeout elapses. | |
| bool | wait (const TimeSpan &timeout) |
| Block the calling thread until the event is set or the timeout elapses. | |
| bool | isWaiting () const |
| Test whether a thread is currently blocked in wait(). | |
| QVariant | data () const |
| Return the arbitrary data payload attached to this event. | |
| void | setData (const QVariant &value) |
| Attach arbitrary data to this event for use by the woken thread. | |
| void | setDebug () |
| Enable verbose debug output for this event. | |
| void | setWakeAllWaiters (bool value) |
| Control whether set() wakes all waiting threads or just one. | |
A very useful object for multi-threaded applications which wish to be be event driven.
It is based on the C# AutoResetEvent class which combines a mutex and a cond_var.
The event driven thread call wait() with an optional timeout.
The event generating thread calls set() and the waiting thread wakes up.
Stephen Punak, May 15 2020
A mutex/condition-variable pair modelling the C# AutoResetEvent.
One thread calls wait() and blocks until another thread calls set(). The event auto-resets after each wakeup unless wakeAllWaiters is enabled, in which case all blocked waiters are woken simultaneously.
Definition at line 31 of file mutexevent.h.
|
inline |
Construct a MutexEvent.
| wakeAllWaiters | If true, set() will wake all waiting threads instead of just one |
Definition at line 38 of file mutexevent.h.
|
inlinevirtual |
Virtual destructor.
Definition at line 45 of file mutexevent.h.
|
inline |
Return the arbitrary data payload attached to this event.
Definition at line 80 of file mutexevent.h.
|
inline |
Test whether a thread is currently blocked in wait().
Definition at line 74 of file mutexevent.h.
|
inline |
Attach arbitrary data to this event for use by the woken thread.
| value | Data to store |
Definition at line 86 of file mutexevent.h.
|
inline |
Enable verbose debug output for this event.
Definition at line 89 of file mutexevent.h.
|
inline |
Control whether set() wakes all waiting threads or just one.
| value | If true, all waiters are woken; if false, only one is woken |
Definition at line 95 of file mutexevent.h.
|
inline |
Block the calling thread until the event is set or the timeout elapses.
| timeout | Maximum wait duration |
Definition at line 65 of file mutexevent.h.
References TimeSpan::totalMilliseconds().
| bool MutexEvent::wait | ( | int | msecs = 0 | ) |
Block the calling thread until the event is set or the timeout elapses.
| msecs | Maximum wait time in milliseconds; 0 means wait indefinitely |