Contents

class

SushiDSP::SpscRing

template <typename T>

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

Declared in
include/SushiDSP/core/SpscRing.hpp

push() runs on the control thread, pop() runs on the audio thread; neither blocks nor allocates after construction.

Public member functions

explicit SpscRing(std::size_t capacity)

Preallocates storage for capacity elements.

Parameters

capacity

Maximum number of elements the ring can hold at once.

bool push(const T &value)

Attempts to enqueue a value.

Producer-thread only.

Parameters

value

The value to enqueue.

Returns

true if enqueued, false if the ring is full.

bool push(const T *values, std::size_t count)

Attempts to enqueue a whole run of values, all of them or none of them.

Producer-thread only. Wait-free: one acquire load, one release store and two copies.

Parameters

values

The values to enqueue.

count

How many values to enqueue.

Returns

true if every value was enqueued, false if the ring holds too little room.

bool pop(T *out, std::size_t count)

Attempts to dequeue a whole run of values, all of them or none of them.

Consumer-thread only. Wait-free: one acquire load, one release store and two copies.

Parameters

out

Receives the dequeued values; at least count elements long.

count

How many values to dequeue.

Returns

true if every value was dequeued, false if the ring holds fewer than count.

bool pop(T &out)

Attempts to dequeue a value.

Consumer-thread only.

Parameters

out

Receives the dequeued value on success.

Returns

true if a value was dequeued, false if the ring is empty.

void clear()

Empties the ring in place, keeping the storage the constructor allocated.

Precondition

Neither the producer nor the consumer is inside push() or pop().

std::size_t capacity() const

The maximum number of elements this ring can hold at once.

Returns

The capacity passed to the constructor.