rippled
Public Member Functions | Private Attributes | List of all members
ripple::ThreadSafeQueue< T > Class Template Reference

Generic thread-safe queue with an optional maximum size Note, we can't use a lockfree queue here, since we need the ability to wait for an element to be added or removed from the queue. More...

Collaboration diagram for ripple::ThreadSafeQueue< T >:
Collaboration graph
[legend]

Public Member Functions

 ThreadSafeQueue (uint32_t maxSize)
 
 ThreadSafeQueue ()=default
 Create a queue with no maximum size. More...
 
void push (T const &elt)
 
void push (T &&elt)
 
pop ()
 

Private Attributes

std::queue< T > queue_
 
std::mutex m_
 
std::condition_variable cv_
 
std::optional< uint32_t > maxSize_
 

Detailed Description

template<class T>
class ripple::ThreadSafeQueue< T >

Generic thread-safe queue with an optional maximum size Note, we can't use a lockfree queue here, since we need the ability to wait for an element to be added or removed from the queue.

These waits are blocking calls.

Definition at line 115 of file ETLHelpers.h.

Constructor & Destructor Documentation

◆ ThreadSafeQueue() [1/2]

template<class T >
ripple::ThreadSafeQueue< T >::ThreadSafeQueue ( uint32_t  maxSize)
explicit
Parameters
maxSizemaximum size of the queue. Calls that would cause the queue to exceed this size will block until free space is available

Definition at line 126 of file ETLHelpers.h.

◆ ThreadSafeQueue() [2/2]

template<class T >
ripple::ThreadSafeQueue< T >::ThreadSafeQueue ( )
default

Create a queue with no maximum size.

Member Function Documentation

◆ push() [1/2]

template<class T >
void ripple::ThreadSafeQueue< T >::push ( T const &  elt)
Parameters
eltelement to push onto queue if maxSize is set, this method will block until free space is available

Definition at line 136 of file ETLHelpers.h.

◆ push() [2/2]

template<class T >
void ripple::ThreadSafeQueue< T >::push ( T &&  elt)
Parameters
eltelement to push onto queue. elt is moved from if maxSize is set, this method will block until free space is available

Definition at line 149 of file ETLHelpers.h.

◆ pop()

template<class T >
T ripple::ThreadSafeQueue< T >::pop ( )
Returns
element popped from queue. Will block until queue is non-empty

Definition at line 161 of file ETLHelpers.h.

Member Data Documentation

◆ queue_

template<class T >
std::queue<T> ripple::ThreadSafeQueue< T >::queue_
private

Definition at line 117 of file ETLHelpers.h.

◆ m_

template<class T >
std::mutex ripple::ThreadSafeQueue< T >::m_
mutableprivate

Definition at line 119 of file ETLHelpers.h.

◆ cv_

template<class T >
std::condition_variable ripple::ThreadSafeQueue< T >::cv_
private

Definition at line 120 of file ETLHelpers.h.

◆ maxSize_

template<class T >
std::optional<uint32_t> ripple::ThreadSafeQueue< T >::maxSize_
private

Definition at line 121 of file ETLHelpers.h.