Thread System 0.3.1
High-performance C++20 thread pool with work stealing and DAG scheduling
Loading...
Searching...
No Matches
kcenon::thread::sync::condition_variable_wrapper Class Reference

Enhanced condition variable wrapper with timeout and predicate support. More...

#include <sync_primitives.h>

Collaboration diagram for kcenon::thread::sync::condition_variable_wrapper:
Collaboration graph

Public Member Functions

 condition_variable_wrapper ()=default
 
 ~condition_variable_wrapper ()=default
 
 condition_variable_wrapper (const condition_variable_wrapper &)=delete
 
condition_variable_wrapperoperator= (const condition_variable_wrapper &)=delete
 
 condition_variable_wrapper (condition_variable_wrapper &&)=default
 
condition_variable_wrapperoperator= (condition_variable_wrapper &&)=default
 
template<typename Lock >
void wait (Lock &lock)
 Wait indefinitely for notification.
 
template<typename Lock , typename Predicate >
void wait (Lock &lock, Predicate predicate)
 Wait with predicate until condition is met.
 
template<typename Lock , typename Rep , typename Period >
bool wait_for (Lock &lock, const std::chrono::duration< Rep, Period > &timeout)
 Wait with timeout.
 
template<typename Lock , typename Rep , typename Period , typename Predicate >
bool wait_for (Lock &lock, const std::chrono::duration< Rep, Period > &timeout, Predicate predicate)
 Wait with timeout and predicate.
 
void notify_one () noexcept
 Notify one waiting thread.
 
void notify_all () noexcept
 Notify all waiting threads.
 
 condition_variable_wrapper ()=default
 
 ~condition_variable_wrapper ()=default
 
 condition_variable_wrapper (const condition_variable_wrapper &)=delete
 
condition_variable_wrapperoperator= (const condition_variable_wrapper &)=delete
 
 condition_variable_wrapper (condition_variable_wrapper &&)=default
 
condition_variable_wrapperoperator= (condition_variable_wrapper &&)=default
 
template<typename Lock >
void wait (Lock &lock)
 Wait indefinitely for notification.
 
template<typename Lock , typename Predicate >
void wait (Lock &lock, Predicate predicate)
 Wait with predicate until condition is met.
 
template<typename Lock , typename Rep , typename Period >
bool wait_for (Lock &lock, const std::chrono::duration< Rep, Period > &timeout)
 Wait with timeout.
 
template<typename Lock , typename Rep , typename Period , typename Predicate >
bool wait_for (Lock &lock, const std::chrono::duration< Rep, Period > &timeout, Predicate predicate)
 Wait with timeout and predicate.
 
void notify_one () noexcept
 Notify one waiting thread.
 
void notify_all () noexcept
 Notify all waiting threads.
 

Private Attributes

std::condition_variable cv_
 

Detailed Description

Enhanced condition variable wrapper with timeout and predicate support.

Definition at line 96 of file sync_primitives.h.

Constructor & Destructor Documentation

◆ condition_variable_wrapper() [1/6]

kcenon::thread::sync::condition_variable_wrapper::condition_variable_wrapper ( )
default

◆ ~condition_variable_wrapper() [1/2]

kcenon::thread::sync::condition_variable_wrapper::~condition_variable_wrapper ( )
default

◆ condition_variable_wrapper() [2/6]

kcenon::thread::sync::condition_variable_wrapper::condition_variable_wrapper ( const condition_variable_wrapper & )
delete

◆ condition_variable_wrapper() [3/6]

kcenon::thread::sync::condition_variable_wrapper::condition_variable_wrapper ( condition_variable_wrapper && )
default

◆ condition_variable_wrapper() [4/6]

kcenon::thread::sync::condition_variable_wrapper::condition_variable_wrapper ( )
default

◆ ~condition_variable_wrapper() [2/2]

kcenon::thread::sync::condition_variable_wrapper::~condition_variable_wrapper ( )
default

◆ condition_variable_wrapper() [5/6]

kcenon::thread::sync::condition_variable_wrapper::condition_variable_wrapper ( const condition_variable_wrapper & )
delete

◆ condition_variable_wrapper() [6/6]

kcenon::thread::sync::condition_variable_wrapper::condition_variable_wrapper ( condition_variable_wrapper && )
default

Member Function Documentation

◆ notify_all() [1/2]

void kcenon::thread::sync::condition_variable_wrapper::notify_all ( )
inlinenoexcept

Notify all waiting threads.

Definition at line 153 of file sync_primitives.h.

153 {
154 cv_.notify_all();
155 }

References cv_.

◆ notify_all() [2/2]

void kcenon::thread::sync::condition_variable_wrapper::notify_all ( )
inlinenoexcept

Notify all waiting threads.

Definition at line 159 of file sync_primitives.h.

159 {
160 cv_.notify_all();
161 }

References cv_.

◆ notify_one() [1/2]

void kcenon::thread::sync::condition_variable_wrapper::notify_one ( )
inlinenoexcept

Notify one waiting thread.

Definition at line 146 of file sync_primitives.h.

146 {
147 cv_.notify_one();
148 }

References cv_.

◆ notify_one() [2/2]

void kcenon::thread::sync::condition_variable_wrapper::notify_one ( )
inlinenoexcept

Notify one waiting thread.

Definition at line 152 of file sync_primitives.h.

152 {
153 cv_.notify_one();
154 }

References cv_.

◆ operator=() [1/4]

condition_variable_wrapper & kcenon::thread::sync::condition_variable_wrapper::operator= ( condition_variable_wrapper && )
default

◆ operator=() [2/4]

condition_variable_wrapper & kcenon::thread::sync::condition_variable_wrapper::operator= ( condition_variable_wrapper && )
default

◆ operator=() [3/4]

condition_variable_wrapper & kcenon::thread::sync::condition_variable_wrapper::operator= ( const condition_variable_wrapper & )
delete

◆ operator=() [4/4]

condition_variable_wrapper & kcenon::thread::sync::condition_variable_wrapper::operator= ( const condition_variable_wrapper & )
delete

◆ wait() [1/4]

template<typename Lock >
void kcenon::thread::sync::condition_variable_wrapper::wait ( Lock & lock)
inline

Wait indefinitely for notification.

Parameters
lockUnique lock that must be held by calling thread

Definition at line 106 of file sync_primitives.h.

106 {
107 cv_.wait(lock);
108 }

References cv_.

◆ wait() [2/4]

template<typename Lock >
void kcenon::thread::sync::condition_variable_wrapper::wait ( Lock & lock)
inline

Wait indefinitely for notification.

Parameters
lockUnique lock that must be held by calling thread

Definition at line 112 of file sync_primitives.h.

112 {
113 cv_.wait(lock);
114 }

References cv_.

◆ wait() [3/4]

template<typename Lock , typename Predicate >
void kcenon::thread::sync::condition_variable_wrapper::wait ( Lock & lock,
Predicate predicate )
inline

Wait with predicate until condition is met.

Parameters
lockUnique lock that must be held by calling thread
predicateFunction that returns true when waiting should stop

Definition at line 116 of file sync_primitives.h.

116 {
117 cv_.wait(lock, predicate);
118 }

References cv_.

◆ wait() [4/4]

template<typename Lock , typename Predicate >
void kcenon::thread::sync::condition_variable_wrapper::wait ( Lock & lock,
Predicate predicate )
inline

Wait with predicate until condition is met.

Parameters
lockUnique lock that must be held by calling thread
predicateFunction that returns true when waiting should stop

Definition at line 122 of file sync_primitives.h.

122 {
123 cv_.wait(lock, predicate);
124 }

References cv_.

◆ wait_for() [1/4]

template<typename Lock , typename Rep , typename Period >
bool kcenon::thread::sync::condition_variable_wrapper::wait_for ( Lock & lock,
const std::chrono::duration< Rep, Period > & timeout )
inline

Wait with timeout.

Parameters
lockUnique lock that must be held by calling thread
timeoutMaximum time to wait
Returns
true if notified before timeout, false if timeout occurred

Definition at line 127 of file sync_primitives.h.

127 {
128 return cv_.wait_for(lock, timeout) == std::cv_status::no_timeout;
129 }

References cv_.

◆ wait_for() [2/4]

template<typename Lock , typename Rep , typename Period >
bool kcenon::thread::sync::condition_variable_wrapper::wait_for ( Lock & lock,
const std::chrono::duration< Rep, Period > & timeout )
inline

Wait with timeout.

Parameters
lockUnique lock that must be held by calling thread
timeoutMaximum time to wait
Returns
true if notified before timeout, false if timeout occurred

Definition at line 133 of file sync_primitives.h.

133 {
134 return cv_.wait_for(lock, timeout) == std::cv_status::no_timeout;
135 }

References cv_.

◆ wait_for() [3/4]

template<typename Lock , typename Rep , typename Period , typename Predicate >
bool kcenon::thread::sync::condition_variable_wrapper::wait_for ( Lock & lock,
const std::chrono::duration< Rep, Period > & timeout,
Predicate predicate )
inline

Wait with timeout and predicate.

Parameters
lockUnique lock that must be held by calling thread
timeoutMaximum time to wait
predicateFunction that returns true when waiting should stop
Returns
true if predicate became true before timeout

Definition at line 139 of file sync_primitives.h.

139 {
140 return cv_.wait_for(lock, timeout, predicate);
141 }

References cv_.

◆ wait_for() [4/4]

template<typename Lock , typename Rep , typename Period , typename Predicate >
bool kcenon::thread::sync::condition_variable_wrapper::wait_for ( Lock & lock,
const std::chrono::duration< Rep, Period > & timeout,
Predicate predicate )
inline

Wait with timeout and predicate.

Parameters
lockUnique lock that must be held by calling thread
timeoutMaximum time to wait
predicateFunction that returns true when waiting should stop
Returns
true if predicate became true before timeout

Definition at line 145 of file sync_primitives.h.

145 {
146 return cv_.wait_for(lock, timeout, predicate);
147 }

References cv_.

Member Data Documentation

◆ cv_

std::condition_variable kcenon::thread::sync::condition_variable_wrapper::cv_
private

Definition at line 158 of file sync_primitives.h.

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


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