C++ features by examples
Synchronized_queue< T, Container > Class Template Reference
Inheritance diagram for Synchronized_queue< T, Container >:
Collaboration diagram for Synchronized_queue< T, Container >:

Public Member Functions

void push (T &&v)
 
optional< reference_wrapper< T > > pull ()
 

Public Attributes

condition_variable cv
 
bool stop = false
 

Detailed Description

template<typename T, class Container = std::queue<T>>
class Synchronized_queue< T, Container >

Definition at line 726 of file patterns.cpp.

Member Function Documentation

◆ pull()

template<typename T , class Container = std::queue<T>>
optional< reference_wrapper< T > > Synchronized_queue< T, Container >::pull ( )
inline

Definition at line 738 of file patterns.cpp.

738 {
739 unique_lock<mutex> lk(mtx);
740 cv.wait(lk, [&] { return !this->empty() || stop; });
741 optional<reference_wrapper<T>> ret;
742 if (stop) {
743 ret = nullopt;
744 } else {
745 ret = make_optional(ref(Container::front()));
746 this->pop();
747 }
748 return ret;
749 };
condition_variable cv
Definition: patterns.cpp:731

◆ push()

template<typename T , class Container = std::queue<T>>
void Synchronized_queue< T, Container >::push ( T &&  v)
inline

Definition at line 733 of file patterns.cpp.

733 {
734 scoped_lock<mutex>{mtx}, Container::push(v);
735 cv.notify_one();
736 };

Member Data Documentation

◆ cv

template<typename T , class Container = std::queue<T>>
condition_variable Synchronized_queue< T, Container >::cv

Definition at line 731 of file patterns.cpp.

◆ stop

template<typename T , class Container = std::queue<T>>
bool Synchronized_queue< T, Container >::stop = false

Definition at line 732 of file patterns.cpp.


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