µOS++ IIIe Reference 7.0.0
The third edition of µOS++, a POSIX inspired open source framework, written in C++
Loading...
Searching...
No Matches
os::estd::condition_variable Class Reference

#include <condition_variable>

Public Types

using native_handle_type = native_type *
 

Public Member Functions

 condition_variable ()
 
 condition_variable (const condition_variable &)=delete
 
 ~condition_variable ()
 
native_handle_type native_handle ()
 
void notify_all () noexcept
 
void notify_one () noexcept
 
condition_variableoperator= (const condition_variable &)=delete
 
void wait (std::unique_lock< mutex > &lock)
 
template<class Predicate_T >
void wait (std::unique_lock< mutex > &lock, Predicate_T pred)
 
template<class Rep_T , class Period_T >
cv_status wait_for (std::unique_lock< mutex > &lock, const std::chrono::duration< Rep_T, Period_T > &rel_time)
 
template<class Rep_T , class Period_T , class Predicate_T >
bool wait_for (std::unique_lock< mutex > &lock, const std::chrono::duration< Rep_T, Period_T > &rel_time, Predicate_T pred)
 
template<class Clock_T , class Duration_T >
cv_status wait_until (std::unique_lock< mutex > &lock, const std::chrono::time_point< Clock_T, Duration_T > &abs_time)
 
template<class Clock_T , class Duration_T , class Predicate_T >
bool wait_until (std::unique_lock< mutex > &lock, const std::chrono::time_point< Clock_T, Duration_T > &abs_time, Predicate_T pred)
 

Protected Types

using Native_clock = os::estd::chrono::systick_clock
 

Protected Attributes

native_type ncv_
 

Private Types

using native_type = os::rtos::condition_variable
 

Detailed Description

Definition at line 76 of file condition_variable.

Member Typedef Documentation

◆ Native_clock

◆ native_handle_type

◆ native_type

Constructor & Destructor Documentation

◆ condition_variable() [1/2]

os::estd::condition_variable::condition_variable ( )
inline

Definition at line 205 of file condition_variable.

206 {
207 }

◆ ~condition_variable()

os::estd::condition_variable::~condition_variable ( )
inline

Definition at line 209 of file condition_variable.

210 {
211 }

◆ condition_variable() [2/2]

os::estd::condition_variable::condition_variable ( const condition_variable )
delete

Member Function Documentation

◆ native_handle()

native_handle_type os::estd::condition_variable::native_handle ( )

◆ notify_all()

void os::estd::condition_variable::notify_all ( )
noexcept

Definition at line 42 of file condition-variable.cpp.

43 {
45 res = ncv_.broadcast ();
46 if (res != os::rtos::result::ok)
47 {
49 static_cast<int> (res),
50 "condition_variable::notify_all() failed");
51 }
52 }
result_t broadcast(void)
Notify all threads waiting for a condition variable.
void __throw_cmsis_error(int ev, const char *what_arg)
@ ok
Function completed; no errors or events occurred.
Definition os-decls.h:179
uint32_t result_t
Type of values returned by RTOS functions.
Definition os-decls.h:95

References os::estd::__throw_cmsis_error(), os::rtos::condition_variable::broadcast(), ncv_, and os::rtos::result::ok.

Referenced by os::estd::condition_variable_any::notify_all().

◆ notify_one()

void os::estd::condition_variable::notify_one ( )
noexcept

Definition at line 29 of file condition-variable.cpp.

30 {
32 res = ncv_.signal ();
33 if (res != os::rtos::result::ok)
34 {
36 static_cast<int> (res),
37 "condition_variable::notify_one() failed");
38 }
39 }
result_t signal(void)
Notify one thread waiting for a condition variable.

References os::estd::__throw_cmsis_error(), ncv_, os::rtos::result::ok, and os::rtos::condition_variable::signal().

Referenced by os::estd::condition_variable_any::notify_one().

◆ operator=()

condition_variable & os::estd::condition_variable::operator= ( const condition_variable )
delete

◆ wait() [1/2]

void os::estd::condition_variable::wait ( std::unique_lock< mutex > &  lock)

Definition at line 55 of file condition-variable.cpp.

56 {
57 if (!lk.owns_lock ())
58 {
60 EPERM, "condition_variable::wait: mutex not locked");
61 }
62 os::rtos::result_t res = ncv_.wait ((*(lk.mutex ()->native_handle ())));
63 if (res != os::rtos::result::ok)
64 {
65 os::estd::__throw_cmsis_error (static_cast<int> (res),
66 "condition_variable wait failed");
67 }
68 }
result_t wait(mutex &mutex)
Wait for a condition variable to be notified.
void __throw_system_error(int ev, const char *what_arg)

References os::estd::__throw_cmsis_error(), os::estd::__throw_system_error(), ncv_, os::rtos::result::ok, and os::rtos::condition_variable::wait().

Referenced by os::estd::condition_variable_any::wait(), and wait().

◆ wait() [2/2]

template<class Predicate_T >
void os::estd::condition_variable::wait ( std::unique_lock< mutex > &  lock,
Predicate_T  pred 
)

Definition at line 215 of file condition_variable.

216 {
217 while (!pred ())
218 wait (lock);
219 }
void wait(std::unique_lock< mutex > &lock)

References wait().

◆ wait_for() [1/2]

template<class Rep_T , class Period_T >
cv_status os::estd::condition_variable::wait_for ( std::unique_lock< mutex > &  lock,
const std::chrono::duration< Rep_T, Period_T > &  rel_time 
)

Definition at line 276 of file condition_variable.

279 {
280 using namespace std::chrono;
281
282 if (rel_time <= rel_time.zero ())
283 {
284 return cv_status::timeout;
285 }
286
288
290 = os::estd::chrono::ceil<std::chrono::duration<
292 rel_time)
293 .count ();
294
296 /*(rtos::mutex &)*/ (*(lock.mutex ()->native_handle ())), ticks);
297
298 return (Native_clock::now () - start_tp) < rel_time
301 }
std::ratio< 1, os::rtos::clock_systick::frequency_hz > period
Definition chrono:74
std::chrono::time_point< systick_clock > time_point
basic time_point type of clock
Definition chrono:79
static time_point now() noexcept
Definition chrono.cpp:48
result_t timed_wait(mutex &mutex, clock::duration_t timeout)
Timed wait for a condition variable to be notified.
port::clock::duration_t duration_t
Type of variables holding clock durations.
Definition os-clocks.h:78
constexpr std::enable_if< std::chrono::__is_duration< _To >::value, _To >::type ceil(std::chrono::duration< Rep_T, Period_T > d)
Definition chrono:258
port::scheduler::state_t lock(void)

References os::estd::chrono::ceil(), ncv_, os::estd::no_timeout, os::estd::chrono::systick_clock::now(), os::rtos::condition_variable::timed_wait(), and os::estd::timeout.

Referenced by wait_until().

◆ wait_for() [2/2]

template<class Rep_T , class Period_T , class Predicate_T >
bool os::estd::condition_variable::wait_for ( std::unique_lock< mutex > &  lock,
const std::chrono::duration< Rep_T, Period_T > &  rel_time,
Predicate_T  pred 
)
inline

Definition at line 305 of file condition_variable.

309 {
310 return wait_until (lock, Native_clock::now () + rel_time,
311 std::move (pred));
312 }
cv_status wait_until(std::unique_lock< mutex > &lock, const std::chrono::time_point< Clock_T, Duration_T > &abs_time)

References os::estd::chrono::systick_clock::now(), and wait_until().

◆ wait_until() [1/2]

template<class Clock_T , class Duration_T >
cv_status os::estd::condition_variable::wait_until ( std::unique_lock< mutex > &  lock,
const std::chrono::time_point< Clock_T, Duration_T > &  abs_time 
)

Definition at line 229 of file condition_variable.

232 {
233 using namespace std::chrono;
234 using clock = Clock_T;
235
236#if 0
237 wait_for (lock, abs_time - Clock_T::now ());
238 return
239 Clock_T::now () < abs_time ?
241#else
242 // Optimise to native (ticks). LLVM compares using the
243 // original clock, which might be more accurate.
245 = std::chrono::duration_cast<Native_clock::duration> (
246 abs_time - clock::now ());
247 return wait_for (lock, rel_time);
248#endif
249 }
std::chrono::duration< rep, period > duration
basic duration type of clock
Definition chrono:76
cv_status wait_for(std::unique_lock< mutex > &lock, const std::chrono::duration< Rep_T, Period_T > &rel_time)
clock_t clock(void)

References clock(), os::estd::no_timeout, os::estd::timeout, and wait_for().

Referenced by wait_for(), os::estd::condition_variable_any::wait_until(), and wait_until().

◆ wait_until() [2/2]

template<class Clock_T , class Duration_T , class Predicate_T >
bool os::estd::condition_variable::wait_until ( std::unique_lock< mutex > &  lock,
const std::chrono::time_point< Clock_T, Duration_T > &  abs_time,
Predicate_T  pred 
)

Definition at line 255 of file condition_variable.

259 {
260 while (!pred ())
261 {
262 if (wait_until (lock, abs_time) == cv_status::timeout)
263 return pred ();
264 }
265 return true;
266 }

References os::estd::timeout, and wait_until().

Member Data Documentation

◆ ncv_

native_type os::estd::condition_variable::ncv_
protected

Definition at line 133 of file condition_variable.

Referenced by notify_all(), notify_one(), wait(), and wait_for().


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