Clio develop
The XRP Ledger API server.
Loading...
Searching...
No Matches
etl::ThreadSafeQueue< T > Class Template Reference

Generic thread-safe queue with a max capacity. More...

#include <ETLHelpers.hpp>

Public Member Functions

 ThreadSafeQueue (uint32_t maxSize)
 Create an instance of the queue.
 
void push (T const &elt)
 Push element onto the queue.
 
void push (T &&elt)
 Push element onto the queue.
 
pop ()
 Pop element from the queue.
 
std::optional< T > tryPop ()
 Attempt to pop an element.
 
std::size_t size () const
 Get the size of the queue.
 

Detailed Description

template<typename T>
class etl::ThreadSafeQueue< T >

Generic thread-safe queue with a max capacity.

Note
(original 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.

Constructor & Destructor Documentation

◆ ThreadSafeQueue()

template<typename T >
etl::ThreadSafeQueue< T >::ThreadSafeQueue ( uint32_t maxSize)
inline

Create an instance of the queue.

Parameters
maxSizemaximum size of the queue. Calls that would cause the queue to exceed this size will block until free space is available.

Member Function Documentation

◆ pop()

template<typename T >
T etl::ThreadSafeQueue< T >::pop ( )
inline

Pop element from the queue.

Note: Will block until queue is non-empty.

Returns
Element popped from queue

◆ push() [1/2]

template<typename T >
void etl::ThreadSafeQueue< T >::push ( T && elt)
inline

Push element onto the queue.

Note: This method will block until free space is available

Parameters
eltElement to push onto queue. Ownership is transferred

◆ push() [2/2]

template<typename T >
void etl::ThreadSafeQueue< T >::push ( T const & elt)
inline

Push element onto the queue.

Note: This method will block until free space is available.

Parameters
eltElement to push onto queue

◆ size()

template<typename T >
std::size_t etl::ThreadSafeQueue< T >::size ( ) const
inline

Get the size of the queue.

Returns
The size of the queue

◆ tryPop()

template<typename T >
std::optional< T > etl::ThreadSafeQueue< T >::tryPop ( )
inline

Attempt to pop an element.

Returns
Element popped from queue or empty optional if queue was empty

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