xenium
Public Member Functions | List of all members
xenium::nikolaev_bounded_queue< T, Policies > Class Template Reference

A bounded lock-free multi-producer/multi-consumer queue. More...

#include <nikolaev_bounded_queue.hpp>

Public Member Functions

 nikolaev_bounded_queue (std::size_t capacity)
 Constructs a new instance with the specified maximum size. More...
 
bool try_push (value_type value)
 Tries to push a new element to the queue. More...
 
bool try_pop (value_type &result)
 Tries to pop an element from the queue. More...
 
std::size_t capacity () const noexcept
 Returns the (rounded) capacity of the queue.
 

Detailed Description

template<class T, class... Policies>
class xenium::nikolaev_bounded_queue< T, Policies >

A bounded lock-free multi-producer/multi-consumer queue.

This implementation is based on the bounded MPMC queue proposed by Nikolaev [Nik19].

The nikoleav_bounded_queue provides lock-free progress guarantee under the condition that the number of threads concurrently operating on the queue is less than the queue's capacity.

Supported policies:

Template Parameters
T
Policieslist of policies to customize the behaviour

Constructor & Destructor Documentation

◆ nikolaev_bounded_queue()

template<class T , class... Policies>
xenium::nikolaev_bounded_queue< T, Policies >::nikolaev_bounded_queue ( std::size_t  capacity)
explicit

Constructs a new instance with the specified maximum size.

Parameters
capacitymax number of elements in the queue; If this is not a power of two, it will be rounded to the next power of two

Member Function Documentation

◆ try_pop()

template<class T , class... Policies>
bool xenium::nikolaev_bounded_queue< T, Policies >::try_pop ( value_type &  result)

Tries to pop an element from the queue.

Progress guarantees: lock-free

Parameters
result
Returns
true if the operation was successful, otherwise false

◆ try_push()

template<class T , class... Policies>
bool xenium::nikolaev_bounded_queue< T, Policies >::try_push ( value_type  value)

Tries to push a new element to the queue.

Progress guarantees: lock-free

Parameters
value
Returns
true if the operation was successful, otherwise false