distortos
v0.7.0
object-oriented C++ RTOS for microcontrollers
|
ConditionVariable is an advanced synchronization primitive. More...
#include "distortos/ConditionVariable.hpp"
Public Member Functions | |
constexpr | ConditionVariable () |
ConditionVariable's constructor. More... | |
~ConditionVariable ()=default | |
ConditionVariable's destructor. More... | |
void | notifyAll () |
Notifies all waiting threads. More... | |
void | notifyOne () |
Notifies one waiting thread. More... | |
int | wait (Mutex &mutex) |
Waits for notification. More... | |
template<typename Predicate > | |
int | wait (Mutex &mutex, Predicate predicate) |
Waits for predicate to become true. More... | |
int | waitFor (Mutex &mutex, TickClock::duration duration) |
Waits for notification for given duration of time. More... | |
template<typename Rep , typename Period > | |
int | waitFor (Mutex &mutex, const std::chrono::duration< Rep, Period > duration) |
Waits for notification for given duration of time. More... | |
template<typename Rep , typename Period , typename Predicate > | |
int | waitFor (Mutex &mutex, const std::chrono::duration< Rep, Period > duration, Predicate predicate) |
Waits for predicate to become true for given duration of time. More... | |
int | waitUntil (Mutex &mutex, TickClock::time_point timePoint) |
Waits for notification until given time point. More... | |
template<typename Duration > | |
int | waitUntil (Mutex &mutex, const std::chrono::time_point< TickClock, Duration > timePoint) |
Waits for notification until given time point. More... | |
template<typename Duration , typename Predicate > | |
int | waitUntil (Mutex &mutex, std::chrono::time_point< TickClock, Duration > timePoint, Predicate predicate) |
Waits for predicate to become true until given time point. More... | |
Private Attributes | |
internal::ThreadList | blockedList_ |
ThreadControlBlock objects blocked on this condition variable. More... | |
ConditionVariable is an advanced synchronization primitive.
Similar to std::condition_variable - http://en.cppreference.com/w/cpp/thread/condition_variable Similar to POSIX pthread_cond_t
|
inline |
ConditionVariable's constructor.
Similar to std::condition_variable::condition_variable() - http://en.cppreference.com/w/cpp/thread/condition_variable/condition_variable Similar to pthread_cond_init() - http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_cond_init.html
|
default |
ConditionVariable's destructor.
Similar to std::condition_variable::~condition_variable() - http://en.cppreference.com/w/cpp/thread/condition_variable/~condition_variable Similar to pthread_cond_destroy() - http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_cond_destroy.html
It shall be safe to destroy an initialized condition variable upon which no threads are currently blocked. Attempting to destroy a condition variable upon which other threads are currently blocked results in undefined behavior.
void distortos::ConditionVariable::notifyAll | ( | ) |
Notifies all waiting threads.
Similar to std::condition_variable::notify_all() - http://en.cppreference.com/w/cpp/thread/condition_variable/notify_all Similar to pthread_cond_broadcast() - http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_cond_signal.html
Unblocks all threads waiting on this condition variable. The notifying thread does not need to hold the same mutex as the one held by the waiting thread(s).
void distortos::ConditionVariable::notifyOne | ( | ) |
Notifies one waiting thread.
Similar to std::condition_variable::notify_one() - http://en.cppreference.com/w/cpp/thread/condition_variable/notify_one Similar to pthread_cond_signal() - http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_cond_signal.html
Unblocks one thread waiting on this condition variable. The notifying thread does not need to hold the same mutex as the one held by the waiting thread(s).
int distortos::ConditionVariable::wait | ( | Mutex & | mutex | ) |
Waits for notification.
Similar to std::condition_variable::wait() - http://en.cppreference.com/w/cpp/thread/condition_variable/wait Similar to pthread_cond_wait() - http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_cond_wait.html
Atomically releases supplied mutex and blocks current thread until the condition variable is notified. The thread will be unblocked when notifyAll() or notifyOne() is executed. It may also be unblocked spuriously. When unblocked, regardless of the reason, lock is reacquired and wait exits.
[in] | mutex | is a reference to mutex which must be owned by calling thread |
int distortos::ConditionVariable::wait | ( | Mutex & | mutex, |
Predicate | predicate | ||
) |
Waits for predicate to become true.
Similar to std::condition_variable::wait() - http://en.cppreference.com/w/cpp/thread/condition_variable/wait Similar to pthread_cond_wait() - http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_cond_wait.html
Overload for wait() which also checks the predicate. This function will return only if the predicate is true.
Predicate | is a type of functor to check the predicate |
[in] | mutex | is a reference to mutex which must be owned by calling thread |
[in] | predicate | is the predicate that will be checked |
int distortos::ConditionVariable::waitFor | ( | Mutex & | mutex, |
TickClock::duration | duration | ||
) |
Waits for notification for given duration of time.
Similar to std::condition_variable::wait_for() - http://en.cppreference.com/w/cpp/thread/condition_variable/wait_for Similar to pthread_cond_timedwait() - http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_cond_timedwait.html#
Atomically releases supplied mutex and blocks current thread until the condition variable is notified. The thread will be unblocked when notifyAll() or notifyOne() is executed or when given duration of time expires. It may also be unblocked spuriously. When unblocked, regardless of the reason, lock is reacquired and wait exits.
[in] | mutex | is a reference to mutex which must be owned by calling thread |
[in] | duration | is the duration after which the wait for notification will be terminated |
|
inline |
Waits for notification for given duration of time.
Similar to std::condition_variable::wait_for() - http://en.cppreference.com/w/cpp/thread/condition_variable/wait_for Similar to pthread_cond_timedwait() - http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_cond_timedwait.html#
Template variant of waitFor(Mutex& mutex, TickClock::duration duration).
Rep | is type of tick counter |
Period | is std::ratio type representing the tick period of the clock, seconds |
[in] | mutex | is a reference to mutex which must be owned by calling thread |
[in] | duration | is the duration after which the wait for notification will be terminated |
|
inline |
Waits for predicate to become true for given duration of time.
Similar to std::condition_variable::wait_for() - http://en.cppreference.com/w/cpp/thread/condition_variable/wait_for Similar to pthread_cond_timedwait() - http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_cond_timedwait.html#
Overload for waitFor() which also checks the predicate. This function will return only if the predicate is true or when given duration of time expires.
Rep | is type of tick counter |
Period | is std::ratio type representing the tick period of the clock, seconds |
Predicate | is a type of functor to check the predicate |
[in] | mutex | is a reference to mutex which must be owned by calling thread |
[in] | duration | is the duration after which the wait for notification will be terminated |
[in] | predicate | is the predicate that will be checked |
int distortos::ConditionVariable::waitUntil | ( | Mutex & | mutex, |
TickClock::time_point | timePoint | ||
) |
Waits for notification until given time point.
Similar to std::condition_variable::wait_until() - http://en.cppreference.com/w/cpp/thread/condition_variable/wait_until Similar to pthread_cond_timedwait() - http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_cond_timedwait.html#
Atomically releases supplied mutex and blocks current thread until the condition variable is notified. The thread will be unblocked when notifyAll() or notifyOne() is executed or when given time point is reached. It may also be unblocked spuriously. When unblocked, regardless of the reason, lock is reacquired and wait exits.
[in] | mutex | is a reference to mutex which must be owned by calling thread |
[in] | timePoint | is the time point at which the wait for notification will be terminated |
|
inline |
Waits for notification until given time point.
Similar to std::condition_variable::wait_until() - http://en.cppreference.com/w/cpp/thread/condition_variable/wait_until Similar to pthread_cond_timedwait() - http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_cond_timedwait.html#
Template variant of waitUntil(Mutex& mutex, TickClock::time_point timePoint).
Duration | is a std::chrono::duration type used to measure duration |
[in] | mutex | is a reference to mutex which must be owned by calling thread |
[in] | timePoint | is the time point at which the wait for notification will be terminated |
int distortos::ConditionVariable::waitUntil | ( | Mutex & | mutex, |
std::chrono::time_point< TickClock, Duration > | timePoint, | ||
Predicate | predicate | ||
) |
Waits for predicate to become true until given time point.
Similar to std::condition_variable::wait_until() - http://en.cppreference.com/w/cpp/thread/condition_variable/wait_until Similar to pthread_cond_timedwait() - http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_cond_timedwait.html#
Overload for waitUntil() which also checks the predicate. This function will return only if the predicate is true or when given time point is reached.
Duration | is a std::chrono::duration type used to measure duration |
Predicate | is a type of functor to check the predicate |
[in] | mutex | is a reference to mutex which must be owned by calling thread |
[in] | timePoint | is the time point at which the wait for notification will be terminated |
[in] | predicate | is the predicate that will be checked |
|
private |
ThreadControlBlock objects blocked on this condition variable.