|
Internal Interface Wrap
API 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 | |
|
defaultnoexcept |
|
defaultnoexcept |
|
delete |
|
delete |
|
inlinenoexcept |
Number of elements the ring can hold (a power of two, 0 before Init()).
|
inlinenoexcept |
Consumer side: drop every queued element.
|
inlinenoexcept |
True when nothing is queued (snapshot).
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.
min_capacity is 0, above kMaxCapacity, or allocation failed.
|
inlinenoexcept |
True after a successful Init().
|
delete |
|
delete |
|
inlinenoexcept |
Pushes refused because the ring was full, since Init() or ResetCounters().
|
inlinenoexcept |
Highest fill level seen, since Init() or ResetCounters().
|
inlinenoexcept |
Free the storage. Not thread-safe.
|
inlinenoexcept |
Zero the overrun and peak counters (the queued elements stay).
|
inlinenoexcept |
Elements queued now (a snapshot when the other side is running).
Consumer side: remove the oldest element into out.
Producer side: append a copy of item.
|
private |
|
private |
next slot to write (producer owned)
Largest capacity Init() accepts.
|
private |
|
private |
refused pushes
|
private |
highest fill level
|
private |
|
private |
next slot to read (consumer owned)