Clio develop
The XRP Ledger API server.
Loading...
Searching...
No Matches
util::StrandedPriorityQueue< T, Compare > Class Template Reference

A wrapper for std::priority_queue that serialises operations using a strand. More...

#include <StrandedPriorityQueue.hpp>

Public Member Functions

 StrandedPriorityQueue (util::async::AnyStrand &&strand, std::optional< std::size_t > limit=std::nullopt)
 Construct a new priority queue on a strand.
 
template<typename I >
requires std::is_same_v<std::decay_t<I>, T>
bool enqueue (I &&item)
 Enqueue a new item onto the queue if space is available.
 
std::optional< T > dequeue ()
 Dequeue the next available item out of the queue.
 
bool empty ()
 Check if the queue is empty.
 

Detailed Description

template<typename T, typename Compare = std::less<T>>
class util::StrandedPriorityQueue< T, Compare >

A wrapper for std::priority_queue that serialises operations using a strand.

Note
This may be a candidate for future improvements if performance proves to be poor (e.g. use a lock free queue)

Constructor & Destructor Documentation

◆ StrandedPriorityQueue()

template<typename T , typename Compare = std::less<T>>
util::StrandedPriorityQueue< T, Compare >::StrandedPriorityQueue ( util::async::AnyStrand && strand,
std::optional< std::size_t > limit = std::nullopt )
inline

Construct a new priority queue on a strand.

Parameters
strandThe strand to use
limitThe limit of items allowed simultaniously in the queue

Member Function Documentation

◆ dequeue()

template<typename T , typename Compare = std::less<T>>
std::optional< T > util::StrandedPriorityQueue< T, Compare >::dequeue ( )
inlinenodiscard

Dequeue the next available item out of the queue.

Note
This function blocks until the item is taken off the queue
Returns
An item if available; nullopt otherwise

◆ empty()

template<typename T , typename Compare = std::less<T>>
bool util::StrandedPriorityQueue< T, Compare >::empty ( )
inlinenodiscard

Check if the queue is empty.

Note
This function blocks until the queue is checked
Returns
true if the queue is empty; false otherwise

◆ enqueue()

template<typename T , typename Compare = std::less<T>>
template<typename I >
requires std::is_same_v<std::decay_t<I>, T>
bool util::StrandedPriorityQueue< T, Compare >::enqueue ( I && item)
inlinenodiscard

Enqueue a new item onto the queue if space is available.

Note
This function blocks until the item is attempted to be added to the queue
Template Parameters
IType of the item to add
Parameters
itemThe item to add
Returns
true if item added to the queue; false otherwise

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