Internal Interface Wrap
API reference
Loading...
Searching...
No Matches
Public Member Functions | Static Public Attributes | Private Attributes | List of all members
HfSpscRing< T > Class Template Reference

#include <HfSpscRing.h>

Public Member Functions

 HfSpscRing () noexcept=default
 
 ~HfSpscRing () noexcept=default
 
 HfSpscRing (const HfSpscRing &)=delete
 
HfSpscRing & operator= (const HfSpscRing &)=delete
 
 HfSpscRing (HfSpscRing &&)=delete
 
HfSpscRing & operator= (HfSpscRing &&)=delete
 
bool Init (uint32_t min_capacity) noexcept
 Allocate storage for at least min_capacity elements.
 
void Release () noexcept
 Free the storage. Not thread-safe.
 
bool IsReady () const noexcept
 True after a successful Init().
 
uint32_t Capacity () const noexcept
 Number of elements the ring can hold (a power of two, 0 before Init()).
 
bool TryPush (const T &item) noexcept
 Producer side: append a copy of item.
 
bool TryPop (T &out) noexcept
 Consumer side: remove the oldest element into out.
 
void Clear () noexcept
 Consumer side: drop every queued element.
 
uint32_t Size () const noexcept
 Elements queued now (a snapshot when the other side is running).
 
bool Empty () const noexcept
 True when nothing is queued (snapshot).
 
uint32_t Overruns () const noexcept
 Pushes refused because the ring was full, since Init() or ResetCounters().
 
uint32_t Peak () const noexcept
 Highest fill level seen, since Init() or ResetCounters().
 
void ResetCounters () noexcept
 Zero the overrun and peak counters (the queued elements stay).
 

Static Public Attributes

static constexpr uint32_t kMaxCapacity = 1U << 16
 Largest capacity Init() accepts.
 

Private Attributes

std::unique_ptr< T[]> slots_ {}
 
uint32_t capacity_ {0U}
 
uint32_t mask_ {0U}
 
std::atomic< uint32_t > head_ {0U}
 next slot to write (producer owned)
 
std::atomic< uint32_t > tail_ {0U}
 next slot to read (consumer owned)
 
std::atomic< uint32_t > overruns_ {0U}
 refused pushes
 
std::atomic< uint32_t > peak_ {0U}
 highest fill level
 

Constructor & Destructor Documentation

◆ HfSpscRing() [1/3]

template<typename T >
HfSpscRing< T >::HfSpscRing ( )
defaultnoexcept

◆ ~HfSpscRing()

template<typename T >
HfSpscRing< T >::~HfSpscRing ( )
defaultnoexcept

◆ HfSpscRing() [2/3]

template<typename T >
HfSpscRing< T >::HfSpscRing ( const HfSpscRing< T > &  )
delete

◆ HfSpscRing() [3/3]

template<typename T >
HfSpscRing< T >::HfSpscRing ( HfSpscRing< T > &&  )
delete

Member Function Documentation

◆ Capacity()

template<typename T >
uint32_t HfSpscRing< T >::Capacity ( ) const
inlinenoexcept

Number of elements the ring can hold (a power of two, 0 before Init()).

◆ Clear()

template<typename T >
void HfSpscRing< T >::Clear ( )
inlinenoexcept

Consumer side: drop every queued element.

◆ Empty()

template<typename T >
bool HfSpscRing< T >::Empty ( ) const
inlinenoexcept

True when nothing is queued (snapshot).

◆ Init()

template<typename T >
bool HfSpscRing< T >::Init ( uint32_t  min_capacity)
inlinenoexcept

Allocate storage for at least min_capacity elements.

Not thread-safe; call before the producer and consumer start. Calling it again replaces the storage and empties the ring.

Returns
false if min_capacity is 0, above kMaxCapacity, or allocation failed.

◆ IsReady()

template<typename T >
bool HfSpscRing< T >::IsReady ( ) const
inlinenoexcept

True after a successful Init().

◆ operator=() [1/2]

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

◆ operator=() [2/2]

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

◆ Overruns()

template<typename T >
uint32_t HfSpscRing< T >::Overruns ( ) const
inlinenoexcept

Pushes refused because the ring was full, since Init() or ResetCounters().

◆ Peak()

template<typename T >
uint32_t HfSpscRing< T >::Peak ( ) const
inlinenoexcept

Highest fill level seen, since Init() or ResetCounters().

◆ Release()

template<typename T >
void HfSpscRing< T >::Release ( )
inlinenoexcept

Free the storage. Not thread-safe.

◆ ResetCounters()

template<typename T >
void HfSpscRing< T >::ResetCounters ( )
inlinenoexcept

Zero the overrun and peak counters (the queued elements stay).

◆ Size()

template<typename T >
uint32_t HfSpscRing< T >::Size ( ) const
inlinenoexcept

Elements queued now (a snapshot when the other side is running).

◆ TryPop()

template<typename T >
bool HfSpscRing< T >::TryPop ( T &  out)
inlinenoexcept

Consumer side: remove the oldest element into out.

Returns
false when the ring is empty.

◆ TryPush()

template<typename T >
bool HfSpscRing< T >::TryPush ( const T &  item)
inlinenoexcept

Producer side: append a copy of item.

Returns
false when the ring is full (the overrun counter is incremented) or not initialised.

Member Data Documentation

◆ capacity_

template<typename T >
uint32_t HfSpscRing< T >::capacity_ {0U}
private

◆ head_

template<typename T >
std::atomic<uint32_t> HfSpscRing< T >::head_ {0U}
private

next slot to write (producer owned)

◆ kMaxCapacity

template<typename T >
constexpr uint32_t HfSpscRing< T >::kMaxCapacity = 1U << 16
staticconstexpr

Largest capacity Init() accepts.

◆ mask_

template<typename T >
uint32_t HfSpscRing< T >::mask_ {0U}
private

◆ overruns_

template<typename T >
std::atomic<uint32_t> HfSpscRing< T >::overruns_ {0U}
private

refused pushes

◆ peak_

template<typename T >
std::atomic<uint32_t> HfSpscRing< T >::peak_ {0U}
private

highest fill level

◆ slots_

template<typename T >
std::unique_ptr<T[]> HfSpscRing< T >::slots_ {}
private

◆ tail_

template<typename T >
std::atomic<uint32_t> HfSpscRing< T >::tail_ {0U}
private

next slot to read (consumer owned)


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