TSDuck Version 3.15-964 (TSDuck - The MPEG Transport Stream Toolkit)
ts::Condition Class Reference

Implementation of the synchronization condition design pattern. More...

Classes

class  ConditionError
 Fatal low-level condition/threading error. More...
 

Public Member Functions

 Condition ()
 Default constructor. More...
 
virtual ~Condition ()
 Destructor.
 
void signal ()
 Signal the condition. More...
 
bool wait (Mutex &mutex, MilliSecond timeout, bool &signaled)
 Wait for the condition to be signaled with a timeout,. More...
 
bool wait (Mutex &mutex, MilliSecond timeout)
 Wait for the condition to be signaled with a timeout and loose error reporting. More...
 

Detailed Description

Implementation of the synchronization condition design pattern.

A condition is a general synchronization mechanism which is associated with a mutex.

Typical usage: A set of shared data is protected using a mutex (ts::Mutex). When some expected modification is performed, the modifier thread signals the condition. When other threads wait for the modification to be performed, they acquire the mutex and wait for the condition.

The implementation of this class is operating system dependent, just like ts::Thread and ts::Mutex.

Constructor & Destructor Documentation

◆ Condition()

ts::Condition::Condition ( )

Default constructor.

Exceptions
ts::Condition::ConditionErrorIn case of operating system error, when the underlying system objects could not be created.

Member Function Documentation

◆ signal()

void ts::Condition::signal ( )

Signal the condition.

If more than one thread wait for the condition, at least one is awaken. It is then the responsibility of the awaken threads to check that the expected situation actually exists.

Returns
true on success and false on error.
Exceptions
ts::Condition::ConditionErrorIn case of operating system error.

◆ wait() [1/2]

bool ts::Condition::wait ( Mutex mutex,
MilliSecond  timeout,
bool &  signaled 
)

Wait for the condition to be signaled with a timeout,.

The calling thread must have acquired the mutex first. The mutex is automatically released while waiting and then automatically re-acquired before returning with a successful status.

Parameters
[in,out]mutexThe mutex to automatically release/acquire.
[in]timeoutMaximum number of milliseconds to wait for the mutex.
[out]signaledSet to true if the condition was successfully signaled and the timeout did not expired.
Returns
True on success and false on error. When the timeout expires, this is not an error: true is returned and the mutex is automatically re-acquired. When returning false, the state of the mutex is undefined (acquired vs. released).

◆ wait() [2/2]

bool ts::Condition::wait ( Mutex mutex,
MilliSecond  timeout 
)
inline

Wait for the condition to be signaled with a timeout and loose error reporting.

The calling thread must have acquired the mutex first. The mutex is automatically released while waiting and then automatically re-acquired before returning with a successful status.

Parameters
[in,out]mutexThe mutex to automatically release/acquire.
[in]timeoutMaximum number of milliseconds to wait for the mutex.
Returns
True on success and false on error or timeout. When false is returned, it is not possible to determine whether this was an error or a timeout and the state of the mutex is undefined (acquired vs. released).

The documentation for this class was generated from the following file: