LogIt++
Header-only, macro-first C++ logging library
Loading...
Searching...
No Matches
logit::detail::MpscRingAny< T > Class Template Reference

Bounded MPSC ring buffer with arbitrary capacity (C++11). More...

#include <MpscRingAny.hpp>

Classes

struct  Cell
 Single cell storing sequence number and raw storage for T. More...
 

Public Member Functions

 MpscRingAny (std::size_t capacity)
 Construct ring with given capacity (>= 2).
 
 ~MpscRingAny ()
 Destroy remaining elements, if any.
 
 MpscRingAny (const MpscRingAny &)=delete
 
MpscRingAny & operator= (const MpscRingAny &)=delete
 
 MpscRingAny (MpscRingAny &&other) noexcept
 Move construct ring, adopting producer/consumer indices.
 
MpscRingAny & operator= (MpscRingAny &&other) noexcept
 Move assign ring, draining existing payload.
 
std::size_t capacity () const noexcept
 Capacity of the ring.
 
template<class U >
bool try_push (U &&v) noexcept
 Try to enqueue value.
 
bool try_pop (T &out) noexcept
 Try to dequeue value into out.
 
bool empty () const noexcept
 Lightweight emptiness check for current consumer position.
 

Private Member Functions

void destroy_all_ () noexcept
 

Private Attributes

std::size_t m_cap
 
std::unique_ptr< Cell[]> m_cells
 
std::atomic< std::size_t > m_enqueue_pos
 
std::atomic< std::size_t > m_dequeue_pos
 

Detailed Description

template<class T>
class logit::detail::MpscRingAny< T >

Bounded MPSC ring buffer with arbitrary capacity (C++11).

Template Parameters
TStored type.
Note
T must be nothrow move-constructible, nothrow move-assignable, and nothrow-destructible because cells are published lock-free.

Definition at line 20 of file MpscRingAny.hpp.

Constructor & Destructor Documentation

◆ MpscRingAny() [1/3]

template<class T >
logit::detail::MpscRingAny< T >::MpscRingAny ( std::size_t capacity)
inlineexplicit

Construct ring with given capacity (>= 2).

Definition at line 35 of file MpscRingAny.hpp.

◆ ~MpscRingAny()

template<class T >
logit::detail::MpscRingAny< T >::~MpscRingAny ( )
inline

Destroy remaining elements, if any.

Definition at line 46 of file MpscRingAny.hpp.

◆ MpscRingAny() [2/3]

template<class T >
logit::detail::MpscRingAny< T >::MpscRingAny ( const MpscRingAny< T > & )
delete

◆ MpscRingAny() [3/3]

template<class T >
logit::detail::MpscRingAny< T >::MpscRingAny ( MpscRingAny< T > && other)
inlinenoexcept

Move construct ring, adopting producer/consumer indices.

Definition at line 54 of file MpscRingAny.hpp.

Member Function Documentation

◆ capacity()

template<class T >
std::size_t logit::detail::MpscRingAny< T >::capacity ( ) const
inlinenoexcept

Capacity of the ring.

Definition at line 82 of file MpscRingAny.hpp.

◆ destroy_all_()

template<class T >
void logit::detail::MpscRingAny< T >::destroy_all_ ( )
inlineprivatenoexcept

Definition at line 169 of file MpscRingAny.hpp.

◆ empty()

template<class T >
bool logit::detail::MpscRingAny< T >::empty ( ) const
inlinenoexcept

Lightweight emptiness check for current consumer position.

Definition at line 156 of file MpscRingAny.hpp.

◆ operator=() [1/2]

template<class T >
MpscRingAny & logit::detail::MpscRingAny< T >::operator= ( const MpscRingAny< T > & )
delete

◆ operator=() [2/2]

template<class T >
MpscRingAny & logit::detail::MpscRingAny< T >::operator= ( MpscRingAny< T > && other)
inlinenoexcept

Move assign ring, draining existing payload.

Definition at line 65 of file MpscRingAny.hpp.

◆ try_pop()

template<class T >
bool logit::detail::MpscRingAny< T >::try_pop ( T & out)
inlinenoexcept

Try to dequeue value into out.

Non-blocking.

Returns
true on success; false if queue is empty.

Definition at line 123 of file MpscRingAny.hpp.

◆ try_push()

template<class T >
template<class U >
bool logit::detail::MpscRingAny< T >::try_push ( U && v)
inlinenoexcept

Try to enqueue value.

Non-blocking.

Returns
true on success; false if queue is full.

Definition at line 87 of file MpscRingAny.hpp.

Member Data Documentation

◆ m_cap

template<class T >
std::size_t logit::detail::MpscRingAny< T >::m_cap
private

Definition at line 189 of file MpscRingAny.hpp.

◆ m_cells

template<class T >
std::unique_ptr<Cell[]> logit::detail::MpscRingAny< T >::m_cells
private

Definition at line 190 of file MpscRingAny.hpp.

◆ m_dequeue_pos

template<class T >
std::atomic<std::size_t> logit::detail::MpscRingAny< T >::m_dequeue_pos
private

Definition at line 192 of file MpscRingAny.hpp.

◆ m_enqueue_pos

template<class T >
std::atomic<std::size_t> logit::detail::MpscRingAny< T >::m_enqueue_pos
private

Definition at line 191 of file MpscRingAny.hpp.


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