Embedded Multicore Building Blocks V1.0.0
Public Member Functions | List of all members
embb::base::ConditionVariable Class Reference

Represents a condition variable for thread synchronization. More...

#include <condition_variable.h>

Public Member Functions

 ConditionVariable ()
 Creates a condition variable. More...
 
void NotifyOne ()
 Wakes up one waiting thread. More...
 
void NotifyAll ()
 Wakes up all waiting threads. More...
 
void Wait (UniqueLock< Mutex > &lock)
 Releases the lock and waits until the thread is woken up. More...
 
bool WaitUntil (UniqueLock< Mutex > &lock, const Time &time)
 Releases the lock and waits until the thread is woken up or the specified time point has passed. More...
 
template<typename Tick >
bool WaitFor (UniqueLock< Mutex > &lock, const Duration< Tick > &duration)
 Releases the lock and waits until the thread is woken up or the specified duration has passed. More...
 

Detailed Description

Represents a condition variable for thread synchronization.

Provides an abstraction from platform-specific condition variable implementations. Condition variables can be waited for with timeouts using relative durations and absolute time points.

This class is essentially a wrapper for the underlying C implementation.

Constructor & Destructor Documentation

embb::base::ConditionVariable::ConditionVariable ( )

Creates a condition variable.

Exceptions
embb::base::ErrorExceptionif initialization failed
Dynamic memory allocation
Potentially allocates dynamic memory
Concurrency
Not thread-safe

Member Function Documentation

void embb::base::ConditionVariable::NotifyOne ( )

Wakes up one waiting thread.

Exceptions
embb::base::ErrorExceptionif notification failed
Concurrency
Thread-safe
See also
NotifyAll(), Wait()
void embb::base::ConditionVariable::NotifyAll ( )

Wakes up all waiting threads.

Exceptions
embb::base::ErrorExceptionif notification failed
Concurrency
Thread-safe
See also
NotifyOne(), Wait()
void embb::base::ConditionVariable::Wait ( UniqueLock< Mutex > &  lock)

Releases the lock and waits until the thread is woken up.

Precondition
The lock has been acquired by the calling thread.
Postcondition
The lock has been re-acquired by the calling thread.
Exceptions
embb::base::ErrorExceptionif waiting failed
Concurrency
Thread-safe
See also
NotifyOne(), NotifyAll()
Note
It is strongly recommended checking the condition in a loop in order to deal with spurious wakeups and situations where another thread has locked the mutex between notification and wakeup.
Parameters
[in,out]lockLock to be released and re-acquired
bool embb::base::ConditionVariable::WaitUntil ( UniqueLock< Mutex > &  lock,
const Time time 
)

Releases the lock and waits until the thread is woken up or the specified time point has passed.

Precondition
The lock has been acquired by the calling thread.
Postcondition
The lock has been re-acquired by the calling thread.
Returns
true if the thread was woken up before the specified time point has passed, otherwise false.
Exceptions
embb::base::ErrorExceptionif an error occurred
Concurrency
Thread-safe
Note
It is strongly recommended checking the condition in a loop in order to deal with spurious wakeups and situations where another thread has locked the mutex between notification and wakeup.
Parameters
[in,out]lockLock to be released and re-acquired
[in]timeAbsolute time point until which the thread maximally waits
template<typename Tick >
bool embb::base::ConditionVariable::WaitFor ( UniqueLock< Mutex > &  lock,
const Duration< Tick > &  duration 
)

Releases the lock and waits until the thread is woken up or the specified duration has passed.

Precondition
The lock has been acquired by the calling thread.
Postcondition
The lock has been re-acquired by the calling thread.
Returns
true if the thread was woken up before the specified duration has passed, otherwise false.
Exceptions
embb::base::ErrorExceptionif an error occurred
Concurrency
Thread-safe
Template Parameters
TickType of tick of the duration. See Duration.
Note
It is strongly recommended checking the condition in a loop in order to deal with spurious wakeups and situations where another thread has locked the mutex between notification and wakeup.
Parameters
[in,out]lockLock to be released and re-acquired
[in]durationRelative time duration the thread maximally waits