#include <conditionvariable.h>
After the condition variable has been constructed its state will be cleared until Set() is called. This state is sticky until someone calls Clear() unless the condition variable has been created as auto-clear.
Public Member Functions | |
MAXON_METHOD void | Clear (Int32 dependencyCnt=1) |
MAXON_METHOD void | AddDependency () |
MAXON_METHOD Bool | Set () |
MAXON_METHOD Bool | Wait (const TimeValue &timeout=TIMEVALUE_INFINITE, WAITMODE mode=WAITMODE::DEFAULT) const |
MAXON_FUNCTION ObservableFinishedBase< ConditionVariableInterface > | ObservableFinished () |
Static Public Member Functions | |
static MAXON_METHOD ConditionVariableInterface * | Alloc (MAXON_SOURCE_LOCATION_DECLARATION) |
static MAXON_METHOD ConditionVariableInterface * | Alloc (MAXON_SOURCE_LOCATION_DECLARATION, Bool isAutoClear) |
Private Member Functions | |
MAXON_INTERFACE_NONVIRTUAL (ConditionVariableInterface, MAXON_REFERENCE_NORMAL, "net.maxon.interface.conditionvariable", MAXON_IMPLEMENTATION_MODULE("net.maxon.kernel")) | |
MAXON_METHOD Result< void > | PrivateAddFinishedObserver (const JobInterfacePOD &observerPod, JobQueueInterface *observerQueue) |
Static Private Member Functions | |
static MAXON_FUNCTION Result< void > | AddFinishedObserver (ConditionVariableInterface *cond, JobInterface *observer, JobQueueInterface *queue=JOBQUEUE_NONE) |
template<typename T > | |
static MAXON_FUNCTION std::enable_if<!STD_IS_REPLACEMENT(convertible, typename std::remove_reference< T >::type, JobInterface *), Result< void > >::type | AddFinishedObserver (ConditionVariableInterface *cond, T &&src, JobQueueInterface *queue=JOBQUEUE_NONE) |
Friends | |
template<typename > | |
struct | ObservableFinishedBase |
|
private |
|
static |
[in] | allocLocation | Source location. |
|
static |
If at all times only one thread waits for a condition variable you can make it auto-clear. This means a Wait() call will automatically clear the condition variable upon return.
MAXON_METHOD void Clear | ( | Int32 | dependencyCnt = 1 | ) |
Clears the condition variable and sets the number of dependencies (the number of threads that have to call Set() before the condition is met). By default this is one. When Clear() is called after Wait() you must make sure that there are no more threads still waiting for the same condition. Only after the last thread has left Wait() you are allowed to call Clear(). Otherwise one of the threads may keep waiting because the condition was cleared before it was able to wake up.
[in] | dependencyCnt | The number of times Set() has to be called before the waiting threads will be woken up. |
MAXON_METHOD void AddDependency | ( | ) |
MAXON_METHOD Bool Set | ( | ) |
Wakes up all threads waiting for this condition (if the dependency count reaches 0, see Clear()). THREADSAFE.
MAXON_METHOD Bool Wait | ( | const TimeValue & | timeout = TIMEVALUE_INFINITE , |
WAITMODE | mode = WAITMODE::DEFAULT |
||
) | const |
Waits until the condition has been set or a certain amount of time has passed. Does not execute other jobs on the current queue while waiting. Therefore waiting for a condition variable in a job might result in a deadlock. It's recommended to call this from a thread only - other uses (e.g. from a job) might be unsafe and dead-lock. THREADSAFE.
[in] | timeout | Maximum wait interval (or TIMEVALUE_INFINITE for no time-out). |
[in] | mode | WAITMODE::DEFAULT by default. WAITMODE::RETURN_ON_CANCEL means that Wait() will return if the caller has been cancelled even if the condition has not been set yet. |
MAXON_FUNCTION ObservableFinishedBase<ConditionVariableInterface> ObservableFinished | ( | ) |
ObservableFinished is an observable that is triggered after the condition is set. Is not supported for auto-clear because it requires a sticky state. THREADSAFE.
|
private |
|
staticprivate |
|
staticprivate |
|
friend |