DSPark 1.6.1
Header-only audio DSP framework in pure C++20 — zero dependencies
Loading...
Searching...
No Matches
SpscQueue.h File Reference

Lock-free single-producer, single-consumer (SPSC) bounded queue. More...

#include <array>
#include <atomic>
#include <cstddef>
#include <type_traits>
Include dependency graph for SpscQueue.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  dspark::SpscQueue< T, Capacity >
 

Namespaces

namespace  dspark
 Main namespace for the DSPark framework.
 

Variables

constexpr std::size_t dspark::kCacheLineSize = 64
 

Detailed Description

Lock-free single-producer, single-consumer (SPSC) bounded queue.

Designed for passing parameter snapshots from a control thread (GUI, automation) to the audio thread without locks or allocations at runtime. Features a local index caching optimization to aggressively minimize CPU cache-line bouncing.

Dependencies: C++20 standard library only (<array>, <atomic>, <cstddef>).

Template Parameters
TElement type. Must be trivially copyable for lock-free safety.
CapacityMaximum number of slots. Must be a power of two for efficient modular arithmetic. Note: Actual usable capacity is (Capacity - 1) to safely distinguish between full and empty states.
// GUI thread (producer):
dspark::SpscQueue<Params, 32> queue; // Can hold up to 31 items
if (!queue.push(newParams))
{
// Queue full: coalesce into shared state, or drop knowingly.
}
// Audio thread (consumer):
Params p;
while (queue.pop(p))
applyParams(p);
bool push(const T &item) noexcept
Pushes an element into the queue (producer side).
Definition SpscQueue.h:80
bool pop(T &item) noexcept
Pops an element from the queue (consumer side).
Definition SpscQueue.h:107

Definition in file SpscQueue.h.