This struct wraps C++ standard library types std::mutex
and std::condition_variable
. It allows one or more threads to sleep until any other thread satisfies a condition and wakes one or all threads up.
this
-pointer to that type and access its interface. The derived type has to provide only one function member: bool isConditionMet()
true
if the condition is fulfilled, otherwise false
.true
if the instance was notified.TDerived | The derived type which provides method isConditionMet. |
Definition at line 78 of file condition.inl.
Public Field Index: | |
std::condition_variable | conditionVariable |
The condition variable used for blocking and notification. | |
DbgConditionAsserter | Dbg |
The debug tool instance. | |
std::mutex | mutex |
The mutex used for locking this instance. | |
Public Method Index: | |
TCondition (const character *dbgName) | |
void | Acquire (ALIB_DBG_TAKE_CI) |
TDerived & | cast () |
void | Release (ALIB_DBG_TAKE_CI) |
void | ReleaseAndNotify (ALIB_DBG_TAKE_CI) |
void | ReleaseAndNotifyAll (ALIB_DBG_TAKE_CI) |
void | WaitForNotification (ALIB_DBG_TAKE_CI) |
void | WaitForNotification (const Ticks &wakeUpTime, const CallerInfo &ci) |
void | WaitForNotification (const Ticks::Duration &maxWaitTimeSpan, const CallerInfo &ci) |
void | WaitForNotification (const Ticks::Duration::TDuration &maxWaitTimeSpan, const CallerInfo &ci) |
std::condition_variable alib::threads::TCondition< TDerived >::conditionVariable |
The condition variable used for blocking and notification.
Definition at line 84 of file condition.inl.
DbgConditionAsserter alib::threads::TCondition< TDerived >::Dbg |
The debug tool instance.
Definition at line 93 of file condition.inl.
std::mutex alib::threads::TCondition< TDerived >::mutex |
The mutex used for locking this instance.
Definition at line 81 of file condition.inl.
|
inline |
Constructor.
dbgName | The name of this instance. Available only with debug-builds. With release-builds, this type is default constructed. Hence, this parameter has to be provided using macro ALIB_DBG, which prunes the name away. |
Definition at line 101 of file condition.inl.
|
inline |
A thread which invokes this method gets registered as the current owner of this object, until the same thread releases the ownership invoking Release. In the case that this object is already owned by another thread, the invoking thread is suspended until ownership can be gained.
Multiple (nested) calls to this method are not supported and constitute undefined behavior. In debug-compilations, an error is raised.
An instance has to be acquired before invoking any of the notifiy- or wait-methods. When return from a notification method, the instance is released. With return from a wait method, the instance is still held.
Definition at line 121 of file condition.inl.
|
inline |
Helper to statically casts this object to the derived type.
*this
cast to a reference of TDerived. Definition at line 88 of file condition.inl.
|
inline |
Releases ownership of this object. If this method is invoked on an object that is not acquired or acquired by a different thread, in debug-compilations an error is raised. In release compilations, this leads to undefined behavior.
Definition at line 147 of file condition.inl.
|
inline |
Unblock a next waiting thread.
As the method name indicates, with this implementation, it is necessary to acquire this object before invoking this method. Internally, the mutex will be released, and thus no separate call to Release is necessary, respectively allowed.
Definition at line 170 of file condition.inl.
|
inline |
Releases the internal mutex and wakes up all sleeping threads.
Definition at line 193 of file condition.inl.
|
inline |
Waits for notification (for an unlimited time).
Before invoking this method, this object has to be acquired. After the wake-up call, the internal mutex is (again) acquired and thus has to be released by the owner.
It is allowed to create (endless) loops that never actively release this instance but call one of the waiting methods instead.
Note that "spurious wake-ups" are internally caught with this implementation.
Definition at line 224 of file condition.inl.
|
inline |
Same as WaitForNotification(ALIB_DBG_TAKE_CI), but takes a point in time at which waiting stops.
wakeUpTime | The point in time to wake up, even if not notified. |
ci | Caller information. Use macro ALIB_COMMA_CALLER_PRUNED with invocations. |
Definition at line 320 of file condition.inl.
|
inline |
Same as WaitForNotification(ALIB_DBG_TAKE_CI), but takes a time span that defines a maximum wait time.
maxWaitTimeSpan | The maximum time to wait. |
ci | Caller information. Use macro ALIB_COMMA_CALLER_PRUNED with invocations. |
Definition at line 300 of file condition.inl.
|
inline |
Same as WaitForNotification(ALIB_DBG_TAKE_CI), but takes a C++ time span that defines a maximum wait time.
maxWaitTimeSpan | The maximum time to wait. |
ci | Caller information. Use macro ALIB_COMMA_CALLER_PRUNED with invocations. |
Definition at line 264 of file condition.inl.