libe3 0.2.5
C++ library for E3AP RAN vendor integration
Loading...
Searching...
No Matches
libe3::MpmcQueue< T > Class Template Reference

Lock-free bounded MPMC ring buffer. More...

#include <mpmc_queue.hpp>

Public Member Functions

 MpmcQueue (size_t min_capacity)
 Construct a queue with at least min_capacity slots.
 ~MpmcQueue ()
 MpmcQueue (const MpmcQueue &)=delete
MpmcQueue & operator= (const MpmcQueue &)=delete
 MpmcQueue (MpmcQueue &&)=delete
MpmcQueue & operator= (MpmcQueue &&)=delete
bool try_push (T &&data)
 Try to enqueue an item (non-blocking, move semantics).
bool try_push (const T &data)
 Try to enqueue an item (copy overload).
bool try_pop (T &data)
 Try to dequeue an item (non-blocking).
size_t size_approx () const noexcept
 Approximate number of items currently in the queue.
bool empty_approx () const noexcept
 Return true if the queue appears empty (approximate).
size_t capacity () const noexcept
 Actual slot capacity (always a power of two).

Detailed Description

template<typename T>
class libe3::MpmcQueue< T >

Lock-free bounded MPMC ring buffer.

Template Parameters
TElement type. Must be default-constructible and movable.

Usage:

// producer:
if (!q.try_push(std::move(msg))) { // queue full }
// consumer:
MyMsg out;
if (q.try_pop(out)) { // use out }
MpmcQueue(size_t min_capacity)
Construct a queue with at least min_capacity slots.

Definition at line 48 of file mpmc_queue.hpp.

Constructor & Destructor Documentation

◆ MpmcQueue() [1/3]

template<typename T>
libe3::MpmcQueue< T >::MpmcQueue ( size_t min_capacity)
inlineexplicit

Construct a queue with at least min_capacity slots.

The actual capacity is rounded up to the next power of two (minimum 2).

Parameters
min_capacityMinimum number of slots (0 is treated as 1).

Definition at line 56 of file mpmc_queue.hpp.

◆ ~MpmcQueue()

template<typename T>
libe3::MpmcQueue< T >::~MpmcQueue ( )
inline

Definition at line 77 of file mpmc_queue.hpp.

◆ MpmcQueue() [2/3]

template<typename T>
libe3::MpmcQueue< T >::MpmcQueue ( const MpmcQueue< T > & )
delete

◆ MpmcQueue() [3/3]

template<typename T>
libe3::MpmcQueue< T >::MpmcQueue ( MpmcQueue< T > && )
delete

Member Function Documentation

◆ capacity()

template<typename T>
size_t libe3::MpmcQueue< T >::capacity ( ) const
inlinenoexcept

Actual slot capacity (always a power of two).

Definition at line 178 of file mpmc_queue.hpp.

◆ empty_approx()

template<typename T>
bool libe3::MpmcQueue< T >::empty_approx ( ) const
inlinenoexcept

Return true if the queue appears empty (approximate).

Definition at line 175 of file mpmc_queue.hpp.

◆ operator=() [1/2]

template<typename T>
MpmcQueue & libe3::MpmcQueue< T >::operator= ( const MpmcQueue< T > & )
delete

◆ operator=() [2/2]

template<typename T>
MpmcQueue & libe3::MpmcQueue< T >::operator= ( MpmcQueue< T > && )
delete

◆ size_approx()

template<typename T>
size_t libe3::MpmcQueue< T >::size_approx ( ) const
inlinenoexcept

Approximate number of items currently in the queue.

Due to concurrent modifications this value may be slightly stale, but is always in [0, capacity()].

Definition at line 168 of file mpmc_queue.hpp.

◆ try_pop()

template<typename T>
bool libe3::MpmcQueue< T >::try_pop ( T & data)
inline

Try to dequeue an item (non-blocking).

Parameters
[out]dataReceives the dequeued item on success.
Returns
true on success; false if the queue is empty.

Definition at line 134 of file mpmc_queue.hpp.

◆ try_push() [1/2]

template<typename T>
bool libe3::MpmcQueue< T >::try_push ( const T & data)
inline

Try to enqueue an item (copy overload).

Definition at line 124 of file mpmc_queue.hpp.

◆ try_push() [2/2]

template<typename T>
bool libe3::MpmcQueue< T >::try_push ( T && data)
inline

Try to enqueue an item (non-blocking, move semantics).

Returns
true on success; false if the queue is full.

Definition at line 94 of file mpmc_queue.hpp.


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