Special Relativity in Financial Modeling 1.0.0
Lorentz transforms, spacetime classification, and geodesic price paths for quantitative finance
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | List of all members
srfm::stream::SPSCRing< T, SIZE > Class Template Reference

Lock-free single-producer / single-consumer ring buffer. More...

#include <spsc_ring.hpp>

Public Member Functions

bool push (T &&item) noexcept
 Try to enqueue one element.
 
bool push_copy (const T &item) noexcept(std::is_nothrow_copy_constructible_v< T >)
 Try to enqueue a copy of one element.
 
std::optional< T > pop () noexcept
 Try to dequeue one element.
 
std::size_t size_approx () const noexcept
 Approximate number of elements currently in the ring.
 
bool empty_approx () const noexcept
 Approximate check for emptiness.
 
bool full_approx () const noexcept
 Approximate check for fullness.
 

Static Public Member Functions

static constexpr std::size_t capacity () noexcept
 Maximum number of elements the ring can hold simultaneously.
 

Detailed Description

template<typename T, std::size_t SIZE>
class srfm::stream::SPSCRing< T, SIZE >

Lock-free single-producer / single-consumer ring buffer.

Template Parameters
TElement type (noexcept move-constructible + move-assignable).
SIZECapacity; must be a power of two.

Definition at line 85 of file spsc_ring.hpp.

Member Function Documentation

◆ capacity()

template<typename T , std::size_t SIZE>
static constexpr std::size_t srfm::stream::SPSCRing< T, SIZE >::capacity ( )
inlinestaticconstexprnoexcept

Maximum number of elements the ring can hold simultaneously.

Definition at line 104 of file spsc_ring.hpp.

◆ empty_approx()

template<typename T , std::size_t SIZE>
bool srfm::stream::SPSCRing< T, SIZE >::empty_approx ( ) const
inlinenoexcept

Approximate check for emptiness.

Non-atomic snapshot — use for monitoring only.

Definition at line 199 of file spsc_ring.hpp.

◆ full_approx()

template<typename T , std::size_t SIZE>
bool srfm::stream::SPSCRing< T, SIZE >::full_approx ( ) const
inlinenoexcept

Approximate check for fullness.

Non-atomic snapshot — use for monitoring only.

Definition at line 209 of file spsc_ring.hpp.

◆ pop()

template<typename T , std::size_t SIZE>
std::optional< T > srfm::stream::SPSCRing< T, SIZE >::pop ( )
inlinenoexcept

Try to dequeue one element.

Returns immediately without blocking.

Returns
std::optional<T> containing the dequeued element, or std::nullopt if the ring is empty.
Note
noexcept — never throws, never allocates.
Call from the consumer thread only.

Definition at line 165 of file spsc_ring.hpp.

◆ push()

template<typename T , std::size_t SIZE>
bool srfm::stream::SPSCRing< T, SIZE >::push ( T &&  item)
inlinenoexcept

Try to enqueue one element.

Moves item into the ring. Returns immediately without blocking.

Parameters
itemElement to enqueue (moved from).
Returns
true on success.
false if the ring is full; item is left in a moved-from state.
Note
noexcept — never throws, never allocates.
Call from the producer thread only.

Definition at line 122 of file spsc_ring.hpp.

◆ push_copy()

template<typename T , std::size_t SIZE>
bool srfm::stream::SPSCRing< T, SIZE >::push_copy ( const T &  item)
inlinenoexcept

Try to enqueue a copy of one element.

Convenience overload for copy-constructible types.

Parameters
itemElement to copy-enqueue.
Returns
true on success, false if full.

Definition at line 146 of file spsc_ring.hpp.

◆ size_approx()

template<typename T , std::size_t SIZE>
std::size_t srfm::stream::SPSCRing< T, SIZE >::size_approx ( ) const
inlinenoexcept

Approximate number of elements currently in the ring.

Not guaranteed to be exact under concurrent use (non-atomic snapshot of two separate atomics). Suitable for monitoring / metrics only.

Definition at line 188 of file spsc_ring.hpp.


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