CppCommon
1.0.4.1
C++ Common Library
|
Condition variable synchronization primitive. More...
#include <condition_variable.h>
Public Member Functions | |
ConditionVariable () | |
ConditionVariable (const ConditionVariable &)=delete | |
ConditionVariable (ConditionVariable &&cv)=delete | |
~ConditionVariable () | |
ConditionVariable & | operator= (const ConditionVariable &)=delete |
ConditionVariable & | operator= (ConditionVariable &&cv)=delete |
void | NotifyOne () |
Notify one of waiting thread about event occurred. More... | |
void | NotifyAll () |
Notify all waiting threads about event occurred. More... | |
void | Wait (CriticalSection &cs) |
Wait until condition variable is notified. More... | |
template<typename TPredicate > | |
void | Wait (CriticalSection &cs, TPredicate predicate) |
Wait until condition variable is notified using the given predicate. More... | |
bool | TryWaitFor (CriticalSection &cs, const Timespan ×pan) |
Try to wait for the given timespan until condition variable is notified. More... | |
template<typename TPredicate > | |
bool | TryWaitFor (CriticalSection &cs, const Timespan ×pan, TPredicate predicate) |
Try to wait for the given timespan until condition variable is notified using the given predicate. More... | |
bool | TryWaitUntil (CriticalSection &cs, const UtcTimestamp ×tamp) |
Try to wait until the given timestamp until condition variable is notified. More... | |
template<typename TPredicate > | |
bool | TryWaitUntil (CriticalSection &cs, const UtcTimestamp ×tamp, TPredicate predicate) |
Try to wait until the given timestamp until condition variable is notified using the given predicate. More... | |
Condition variable synchronization primitive.
Condition variable is a synchronization primitive that enable threads to wait until a particular condition occurs. Condition variables are user-mode objects that cannot be shared across processes.
Condition variables enable threads to atomically release a lock and enter the sleeping state. They can be used with critical sections. Condition variables support operations that "notify one" or "notify all" waiting threads. After a thread is woken, it re-acquires the lock it released when the thread entered the sleeping state.
Thread-safe.
https://en.wikipedia.org/wiki/Monitor_(synchronization)
Definition at line 32 of file condition_variable.h.
CppCommon::ConditionVariable::ConditionVariable | ( | ) |
Definition at line 120 of file condition_variable.cpp.
|
delete |
|
delete |
CppCommon::ConditionVariable::~ConditionVariable | ( | ) |
Definition at line 131 of file condition_variable.cpp.
void CppCommon::ConditionVariable::NotifyAll | ( | ) |
Notify all waiting threads about event occurred.
Unblocks all threads currently waiting for this condition. If no threads are waiting, the function does nothing.
Will not block.
Definition at line 138 of file condition_variable.cpp.
void CppCommon::ConditionVariable::NotifyOne | ( | ) |
Notify one of waiting thread about event occurred.
Unblocks one of the threads currently waiting for this condition. If no threads are waiting, the function does nothing. If more than one, it is unspecified which of the threads is selected.
Will not block.
Definition at line 137 of file condition_variable.cpp.
|
delete |
|
delete |
bool CppCommon::ConditionVariable::TryWaitFor | ( | CriticalSection & | cs, |
const Timespan & | timespan | ||
) |
Try to wait for the given timespan until condition variable is notified.
The execution of the current thread (which shall have locked critical section) is blocked during timespan, or until notified (if the latter happens first).
Will block for the given timespan in the worst case.
cs | - Critical section (must be locked) |
timespan | - Timespan to wait for the condition variable notification |
Definition at line 142 of file condition_variable.cpp.
bool CppCommon::ConditionVariable::TryWaitFor | ( | CriticalSection & | cs, |
const Timespan & | timespan, | ||
TPredicate | predicate | ||
) |
Try to wait for the given timespan until condition variable is notified using the given predicate.
This method is equivalent to:
Will block for the given timespan in the worst case.
cs | - Critical section (must be locked) |
timespan | - Timespan to wait for the condition variable notification |
predicate | - Predicate to check |
Definition at line 19 of file condition_variable.inl.
|
inline |
Try to wait until the given timestamp until condition variable is notified.
The execution of the current thread (which shall have locked critical section) is blocked either until notified or until timestamp, whichever happens first.
Will block until the given timestamp in the worst case.
cs | - Critical section (must be locked) |
timestamp | - Timestamp to stop wait for the condition variable notification |
Definition at line 131 of file condition_variable.h.
|
inline |
Try to wait until the given timestamp until condition variable is notified using the given predicate.
This method is equivalent to:
Will block until the given timestamp in the worst case.
cs | - Critical section (must be locked) |
timestamp | - Timestamp to stop wait for the condition variable notification |
predicate | - Predicate to check |
Definition at line 148 of file condition_variable.h.
void CppCommon::ConditionVariable::Wait | ( | CriticalSection & | cs | ) |
Wait until condition variable is notified.
The execution of the current thread (which shall have locked critical section) is blocked until notified.
Will block.
cs | - Critical section (must be locked) |
Definition at line 140 of file condition_variable.cpp.
void CppCommon::ConditionVariable::Wait | ( | CriticalSection & | cs, |
TPredicate | predicate | ||
) |
Wait until condition variable is notified using the given predicate.
This method is equivalent to:
Will block.
cs | - Critical section (must be locked) |
predicate | - Predicate to check |
Definition at line 12 of file condition_variable.inl.