ConditionVariableInterface Class Reference

#include <conditionvariable.h>

Detailed Description

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< ConditionVariableInterfaceObservableFinished ()
 

Static Public Member Functions

static MAXON_METHOD ConditionVariableInterfaceAlloc (MAXON_SOURCE_LOCATION_DECLARATION)
 
static MAXON_METHOD ConditionVariableInterfaceAlloc (MAXON_SOURCE_LOCATION_DECLARATION, Bool isAutoClear)
 

Private Member Functions

 MAXON_INTERFACE_NONVIRTUAL (ConditionVariableInterface, MAXON_REFERENCE_NORMAL, "net.maxon.interface.conditionvariable")
 
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
 

Member Function Documentation

◆ MAXON_INTERFACE_NONVIRTUAL()

MAXON_INTERFACE_NONVIRTUAL ( ConditionVariableInterface  ,
MAXON_REFERENCE_NORMAL  ,
"net.maxon.interface.conditionvariable"   
)
private

◆ Alloc() [1/2]

Parameters
[in]allocLocationSource location.

◆ Alloc() [2/2]

static MAXON_METHOD ConditionVariableInterface* Alloc ( MAXON_SOURCE_LOCATION_DECLARATION  ,
Bool  isAutoClear 
)
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.

Parameters
[in]allocLocationSource location.
[in]isAutoClearTrue: Wait() will automatically clear the condition variable. False: The state is sticky until Clear() is called.

◆ Clear()

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.

Parameters
[in]dependencyCntThe number of times Set() has to be called before the waiting threads will be woken up.

◆ AddDependency()

MAXON_METHOD void AddDependency ( )

Adds another dependency to the condition, e.g. another thread that has to call Set() before the state is considered set. The condition state must not be set yet. This means you must call this from a thread which hasn't done its Set() call yet. THREADSAFE.

◆ Set()

MAXON_METHOD Bool Set ( )

Wakes up all threads waiting for this condition (if the dependency count reaches 0, see Clear()). THREADSAFE.

Returns
True if successful.

◆ Wait()

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.

Parameters
[in]timeoutMaximum wait interval (or TIMEVALUE_INFINITE for no time-out).
[in]modeWAITMODE::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.
Returns
True if the condition has been set, false for time out or error.

◆ 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.

Returns
Custom observable.

◆ PrivateAddFinishedObserver()

MAXON_METHOD Result<void> PrivateAddFinishedObserver ( const JobInterfacePOD &  observerPod,
JobQueueInterface observerQueue 
)
private

◆ AddFinishedObserver() [1/2]

static MAXON_FUNCTION Result<void> AddFinishedObserver ( ConditionVariableInterface cond,
JobInterface observer,
JobQueueInterface queue = JOBQUEUE_NONE 
)
staticprivate

◆ AddFinishedObserver() [2/2]

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 
)
staticprivate

Friends And Related Function Documentation

◆ ObservableFinishedBase

friend struct ObservableFinishedBase
friend