Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
pulp::runtime::SpscRingIndex Class Reference

#include <spsc_ring_index.hpp>

Public Member Functions

 SpscRingIndex (int capacity) noexcept
 Construct an SpscRingIndex that manages indices in [0, capacity).
int capacity () const noexcept
 Total size of the managed buffer in items.
int num_ready () const noexcept
 Number of items currently available to read.
int free_space () const noexcept
 Free space (in items) available for new writes.
void reset () noexcept
 Reset the cursors back to empty.
void prepare_to_write (int num_to_write, int &start_1, int &size_1, int &start_2, int &size_2) const noexcept
 Plan a write of up to num_to_write items.
void finish_write (int num_written) noexcept
 Advance the write cursor by num_written items.
void prepare_to_read (int num_to_read, int &start_1, int &size_1, int &start_2, int &size_2) const noexcept
 Plan a read of up to num_to_read items.
void finish_read (int num_read) noexcept
 Advance the read cursor by num_read items.
 SpscRingIndex (const SpscRingIndex &)=delete
SpscRingIndex & operator= (const SpscRingIndex &)=delete
 SpscRingIndex (SpscRingIndex &&)=delete
SpscRingIndex & operator= (SpscRingIndex &&)=delete

Constructor & Destructor Documentation

◆ SpscRingIndex() [1/3]

pulp::runtime::SpscRingIndex::SpscRingIndex ( int capacity)
inlineexplicitnoexcept

Construct an SpscRingIndex that manages indices in [0, capacity).

capacity is the size of the caller-owned buffer in items. One slot is reserved internally as the empty/full sentinel, so the maximum number of items that can ever be queued is capacity - 1. Pick a capacity one larger than the worst-case queue depth you need.

◆ SpscRingIndex() [2/3]

pulp::runtime::SpscRingIndex::SpscRingIndex ( const SpscRingIndex & )
delete

◆ SpscRingIndex() [3/3]

pulp::runtime::SpscRingIndex::SpscRingIndex ( SpscRingIndex && )
delete

Member Function Documentation

◆ capacity()

int pulp::runtime::SpscRingIndex::capacity ( ) const
inlinenoexcept

Total size of the managed buffer in items.

◆ finish_read()

void pulp::runtime::SpscRingIndex::finish_read ( int num_read)
inlinenoexcept

Advance the read cursor by num_read items.

◆ finish_write()

void pulp::runtime::SpscRingIndex::finish_write ( int num_written)
inlinenoexcept

Advance the write cursor by num_written items.

Must be called after the caller has copied data into the ranges returned by prepare_to_write(). Passing more than the prepared sum is a programming error and is clamped to keep the fifo coherent.

◆ free_space()

int pulp::runtime::SpscRingIndex::free_space ( ) const
inlinenoexcept

Free space (in items) available for new writes.

The fifo reserves one slot internally, so this is at most capacity - 1.

◆ num_ready()

int pulp::runtime::SpscRingIndex::num_ready ( ) const
inlinenoexcept

Number of items currently available to read.

◆ operator=() [1/2]

SpscRingIndex & pulp::runtime::SpscRingIndex::operator= ( const SpscRingIndex & )
delete

◆ operator=() [2/2]

SpscRingIndex & pulp::runtime::SpscRingIndex::operator= ( SpscRingIndex && )
delete

◆ prepare_to_read()

void pulp::runtime::SpscRingIndex::prepare_to_read ( int num_to_read,
int & start_1,
int & size_1,
int & start_2,
int & size_2 ) const
inlinenoexcept

Plan a read of up to num_to_read items.

Returns two ranges the caller may copy out of its buffer. Sum is min(num_to_read, num_ready()). The cursor is NOT advanced until finish_read() is called.

◆ prepare_to_write()

void pulp::runtime::SpscRingIndex::prepare_to_write ( int num_to_write,
int & start_1,
int & size_1,
int & start_2,
int & size_2 ) const
inlinenoexcept

Plan a write of up to num_to_write items.

Returns two index ranges [start_1, start_1+size_1) and [start_2, start_2+size_2) covering contiguous regions of the caller-owned buffer that may be filled. size_2 is non-zero only when the write wraps past capacity. The sum size_1 + size_2 is min(num_to_write, free_space()). The cursor is NOT advanced until finish_write() is called.

◆ reset()

void pulp::runtime::SpscRingIndex::reset ( )
inlinenoexcept

Reset the cursors back to empty.

Not thread-safe — the caller must guarantee neither producer nor consumer is active.


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