distortos  v0.4.0
object-oriented C++ RTOS for microcontrollers
distortos::ConditionVariable Class Reference

ConditionVariable is an advanced synchronization primitive. More...

#include <ConditionVariable.hpp>

Collaboration diagram for distortos::ConditionVariable:
[legend]

Public Member Functions

constexpr ConditionVariable ()
 ConditionVariable constructor. 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...
 

Detailed Description

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

Constructor & Destructor Documentation

◆ ConditionVariable()

constexpr distortos::ConditionVariable::ConditionVariable ( )
inline

ConditionVariable 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

Here is the call graph for this function:

Member Function Documentation

◆ notifyAll()

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

Here is the call graph for this function:
Here is the caller graph for this function:

◆ notifyOne()

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

Here is the call graph for this function:
Here is the caller graph for this function:

◆ wait() [1/2]

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.

Warning
This function must not be called from interrupt context!
Parameters
[in]mutexis a reference to mutex which must be owned by calling thread
Returns
zero if the wait was completed successfully, error code otherwise:
  • EPERM - the mutex type is ErrorChecking or Recursive, and the current thread does not own the mutex;
Here is the call graph for this function:
Here is the caller graph for this function:

◆ wait() [2/2]

template<typename Predicate >
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.

Warning
This function must not be called from interrupt context!
Template Parameters
Predicateis a type of functor to check the predicate
Parameters
[in]mutexis a reference to mutex which must be owned by calling thread
[in]predicateis the predicate that will be checked
Returns
zero if the wait was completed successfully, error code otherwise:
  • EPERM - the mutex type is ErrorChecking or Recursive, and the current thread does not own the mutex;
Here is the call graph for this function:

◆ waitFor() [1/3]

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.

Warning
This function must not be called from interrupt context!
Parameters
[in]mutexis a reference to mutex which must be owned by calling thread
[in]durationis the duration after which the wait for notification will be terminated
Returns
zero if the wait was completed successfully, error code otherwise:
  • EPERM - the mutex type is ErrorChecking or Recursive, and the current thread does not own the mutex;
  • ETIMEDOUT - no notification was received before the specified timeout expired;
Here is the call graph for this function:
Here is the caller graph for this function:

◆ waitFor() [2/3]

template<typename Rep , typename Period >
int distortos::ConditionVariable::waitFor ( Mutex mutex,
const std::chrono::duration< Rep, Period >  duration 
)
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).

Warning
This function must not be called from interrupt context!
Template Parameters
Repis type of tick counter
Periodis std::ratio type representing the tick period of the clock, seconds
Parameters
[in]mutexis a reference to mutex which must be owned by calling thread
[in]durationis the duration after which the wait for notification will be terminated
Returns
zero if the wait was completed successfully, error code otherwise:
  • EPERM - the mutex type is ErrorChecking or Recursive, and the current thread does not own the mutex;
  • ETIMEDOUT - no notification was received before the specified timeout expired;
Here is the call graph for this function:

◆ waitFor() [3/3]

template<typename Rep , typename Period , typename Predicate >
int distortos::ConditionVariable::waitFor ( Mutex mutex,
const std::chrono::duration< Rep, Period >  duration,
Predicate  predicate 
)
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.

Warning
This function must not be called from interrupt context!
Template Parameters
Repis type of tick counter
Periodis std::ratio type representing the tick period of the clock, seconds
Predicateis a type of functor to check the predicate
Parameters
[in]mutexis a reference to mutex which must be owned by calling thread
[in]durationis the duration after which the wait for notification will be terminated
[in]predicateis the predicate that will be checked
Returns
zero if the wait was completed successfully, error code otherwise:
  • EPERM - the mutex type is ErrorChecking or Recursive, and the current thread does not own the mutex;
  • ETIMEDOUT - no notification was received before the specified timeout expired;
Here is the call graph for this function:

◆ waitUntil() [1/3]

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.

Warning
This function must not be called from interrupt context!
Parameters
[in]mutexis a reference to mutex which must be owned by calling thread
[in]timePointis the time point at which the wait for notification will be terminated
Returns
zero if the wait was completed successfully, error code otherwise:
  • EPERM - the mutex type is ErrorChecking or Recursive, and the current thread does not own the mutex;
  • ETIMEDOUT - no notification was received before the specified timeout expired;
Here is the call graph for this function:
Here is the caller graph for this function:

◆ waitUntil() [2/3]

template<typename Duration >
int distortos::ConditionVariable::waitUntil ( Mutex mutex,
const std::chrono::time_point< TickClock, Duration >  timePoint 
)
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).

Warning
This function must not be called from interrupt context!
Template Parameters
Durationis a std::chrono::duration type used to measure duration
Parameters
[in]mutexis a reference to mutex which must be owned by calling thread
[in]timePointis the time point at which the wait for notification will be terminated
Returns
zero if the wait was completed successfully, error code otherwise:
  • EPERM - the mutex type is ErrorChecking or Recursive, and the current thread does not own the mutex;
  • ETIMEDOUT - no notification was received before the specified timeout expired;
Here is the call graph for this function:

◆ waitUntil() [3/3]

template<typename Duration , typename Predicate >
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.

Warning
This function must not be called from interrupt context!
Template Parameters
Durationis a std::chrono::duration type used to measure duration
Predicateis a type of functor to check the predicate
Parameters
[in]mutexis a reference to mutex which must be owned by calling thread
[in]timePointis the time point at which the wait for notification will be terminated
[in]predicateis the predicate that will be checked
Returns
zero if the wait was completed successfully, error code otherwise:
  • EPERM - the mutex type is ErrorChecking or Recursive, and the current thread does not own the mutex;
  • ETIMEDOUT - no notification was received before the specified timeout expired;
Here is the call graph for this function:

Member Data Documentation

◆ blockedList_

internal::ThreadList distortos::ConditionVariable::blockedList_
private

ThreadControlBlock objects blocked on this condition variable.


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