µ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_any Class Reference

#include <condition_variable>

Public Member Functions

 condition_variable_any ()
 
 condition_variable_any (const condition_variable_any &)=delete
 
 ~condition_variable_any ()
 
void notify_all () noexcept
 
void notify_one () noexcept
 
condition_variable_anyoperator= (const condition_variable_any &)=delete
 
template<class Lock_T >
void wait (Lock_T &lock)
 
template<class Lock_T , class Predicate_T >
void wait (Lock_T &lock, Predicate_T pred)
 
template<class Lock_T , class Rep_T , class Period_T >
cv_status wait_for (Lock_T &lock, const std::chrono::duration< Rep_T, Period_T > &rel_time)
 
template<class Lock_T , class Rep_T , class Period_T , class Predicate_T >
bool wait_for (Lock_T &lock, const std::chrono::duration< Rep_T, Period_T > &rel_time, Predicate_T pred)
 
template<class Lock_T , class Clock_T , class Duration_T >
cv_status wait_until (Lock_T &lock, const std::chrono::time_point< Clock_T, Duration_T > &abs_time)
 
template<class Lock_T , class Clock_T , class Duration_T , class Predicate_T >
bool wait_until (Lock_T &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

condition_variable cv_
 
std::shared_ptr< mutexmx_
 

Detailed Description

Definition at line 141 of file condition_variable.

Member Typedef Documentation

◆ Native_clock

Constructor & Destructor Documentation

◆ condition_variable_any() [1/2]

os::estd::condition_variable_any::condition_variable_any ( )
inline

Definition at line 318 of file condition_variable.

319 : cv_{}, //
320 mx_{ std::make_shared<mutex> () }
321 {
322 }

◆ ~condition_variable_any()

os::estd::condition_variable_any::~condition_variable_any ( )
inline

Definition at line 324 of file condition_variable.

325 {
326 }

◆ condition_variable_any() [2/2]

os::estd::condition_variable_any::condition_variable_any ( const condition_variable_any )
delete

Member Function Documentation

◆ notify_all()

void os::estd::condition_variable_any::notify_all ( )
inlinenoexcept

Definition at line 336 of file condition_variable.

337 {
338 std::lock_guard<mutex> lock (*mx_);
339 cv_.notify_all ();
340 }
port::scheduler::state_t lock(void)

References cv_, mx_, and os::estd::condition_variable::notify_all().

◆ notify_one()

void os::estd::condition_variable_any::notify_one ( )
inlinenoexcept

Definition at line 329 of file condition_variable.

330 {
331 std::lock_guard<mutex> lock (*mx_);
332 cv_.notify_one ();
333 }

References cv_, mx_, and os::estd::condition_variable::notify_one().

◆ operator=()

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

◆ wait() [1/2]

template<class Lock_T >
void os::estd::condition_variable_any::wait ( Lock_T &  lock)

Definition at line 359 of file condition_variable.

360 {
361 std::shared_ptr<mutex> mx = mx_;
362 std::unique_lock<mutex> lk (*mx);
363 lock.unlock ();
364 std::unique_ptr<Lock_T, __lock_external> lxx (&lock);
365 std::lock_guard<std::unique_lock<mutex>> lx (lk, std::adopt_lock);
366
367 cv_.wait (lk);
368 // mx.unlock()
369 // lock.lock()
370 }
void wait(std::unique_lock< mutex > &lock)

References cv_, mx_, and os::estd::condition_variable::wait().

Referenced by wait().

◆ wait() [2/2]

template<class Lock_T , class Predicate_T >
void os::estd::condition_variable_any::wait ( Lock_T &  lock,
Predicate_T  pred 
)
inline

Definition at line 374 of file condition_variable.

375 {
376 while (!pred ())
377 wait (lock);
378 }

References wait().

◆ wait_for() [1/2]

template<class Lock_T , class Rep_T , class Period_T >
cv_status os::estd::condition_variable_any::wait_for ( Lock_T &  lock,
const std::chrono::duration< Rep_T, Period_T > &  rel_time 
)
inline

Definition at line 416 of file condition_variable.

418 {
419 return wait_until (lock, Native_clock::now () + rel_time);
420 }
static time_point now() noexcept
Definition chrono.cpp:48
cv_status wait_until(Lock_T &lock, const std::chrono::time_point< Clock_T, Duration_T > &abs_time)

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

◆ wait_for() [2/2]

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

Definition at line 424 of file condition_variable.

427 {
428 return wait_until (lock, Native_clock::now () + rel_time,
429 std::move (pred));
430 }

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

◆ wait_until() [1/2]

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

Definition at line 382 of file condition_variable.

385 {
386 std::shared_ptr<mutex> mx = mx_;
387 std::unique_lock<mutex> lk (*mx);
388 lock.unlock ();
389 std::unique_ptr<Lock_T, __lock_external> lxx (&lock);
390 std::lock_guard<std::unique_lock<mutex>> lx (lk, std::adopt_lock);
391
392 return cv_.wait_until (lk, abs_time);
393 // mx.unlock()
394 // lock.lock()
395 }
cv_status wait_until(std::unique_lock< mutex > &lock, const std::chrono::time_point< Clock_T, Duration_T > &abs_time)

References cv_, mx_, and os::estd::condition_variable::wait_until().

Referenced by wait_for(), wait_for(), and wait_until().

◆ wait_until() [2/2]

template<class Lock_T , class Clock_T , class Duration_T , class Predicate_T >
bool os::estd::condition_variable_any::wait_until ( Lock_T &  lock,
const std::chrono::time_point< Clock_T, Duration_T > &  abs_time,
Predicate_T  pred 
)
inline

Definition at line 399 of file condition_variable.

403 {
404 while (!pred ())
405 {
406 if (wait_until (lock, abs_time) == cv_status::timeout)
407 {
408 return pred ();
409 }
410 }
411 return true;
412 }

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

Member Data Documentation

◆ cv_

condition_variable os::estd::condition_variable_any::cv_
protected

Definition at line 192 of file condition_variable.

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

◆ mx_

std::shared_ptr<mutex> os::estd::condition_variable_any::mx_
protected

Definition at line 193 of file condition_variable.

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


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