MayaFlux 0.1.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
MayaFlux::Journal::RingBuffer< T, Capacity > Class Template Reference

Lock-free SPSC (Single Producer Single Consumer) ring buffer. More...

#include <RingBuffer.hpp>

+ Inheritance diagram for MayaFlux::Journal::RingBuffer< T, Capacity >:
+ Collaboration diagram for MayaFlux::Journal::RingBuffer< T, Capacity >:

Public Member Functions

 RingBuffer ()
 
bool try_push (const T &item) noexcept
 Attempt to write an element (wait-free)
 
std::optional< T > try_pop () noexcept
 Attempt to read an element.
 
bool empty () const noexcept
 Check if buffer is empty.
 
size_t size () const noexcept
 Get approximate size (may be stale)
 

Static Public Member Functions

static constexpr size_t capacity () noexcept
 Get buffer capacity.
 

Static Private Member Functions

static constexpr size_t increment (size_t index) noexcept
 

Private Attributes

std::atomic< size_t > m_write_index
 
std::atomic< size_t > m_read_index
 
std::array< T, Capacity > m_buffer
 

Detailed Description

template<typename T, size_t Capacity>
class MayaFlux::Journal::RingBuffer< T, Capacity >

Lock-free SPSC (Single Producer Single Consumer) ring buffer.

Designed for wait-free writes from realtime threads. Uses atomic operations and careful memory ordering.

Template Parameters
TElement type (must be trivially copyable)
CapacityBuffer size (must be power of 2 for fast modulo)

Definition at line 15 of file RingBuffer.hpp.


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