DSPark 1.6.1
Header-only audio DSP framework in pure C++20 — zero dependencies
Loading...
Searching...
No Matches
dspark::SpscQueue< T, Capacity > Class Template Reference

#include <SpscQueue.h>

Public Member Functions

 SpscQueue ()=default
 Constructs an empty SPSC queue.
 
 SpscQueue (const SpscQueue &)=delete
 
SpscQueueoperator= (const SpscQueue &)=delete
 
bool push (const T &item) noexcept
 Pushes an element into the queue (producer side).
 
bool pop (T &item) noexcept
 Pops an element from the queue (consumer side).
 
std::size_t sizeApprox () const noexcept
 Returns the approximate number of elements in the queue.
 
bool empty () const noexcept
 Returns true if the queue appears empty (approximate).
 

Static Public Member Functions

static constexpr std::size_t capacity () noexcept
 Usable capacity: one slot is reserved to tell full from empty.
 

Detailed Description

template<typename T, std::size_t Capacity = 32>
class dspark::SpscQueue< T, Capacity >

Definition at line 57 of file SpscQueue.h.

Constructor & Destructor Documentation

◆ SpscQueue() [1/2]

template<typename T , std::size_t Capacity = 32>
dspark::SpscQueue< T, Capacity >::SpscQueue ( )
default

Constructs an empty SPSC queue.

◆ SpscQueue() [2/2]

template<typename T , std::size_t Capacity = 32>
dspark::SpscQueue< T, Capacity >::SpscQueue ( const SpscQueue< T, Capacity > &  )
delete

Member Function Documentation

◆ capacity()

template<typename T , std::size_t Capacity = 32>
static constexpr std::size_t dspark::SpscQueue< T, Capacity >::capacity ( )
inlinestaticconstexprnoexcept

Usable capacity: one slot is reserved to tell full from empty.

Definition at line 142 of file SpscQueue.h.

◆ empty()

template<typename T , std::size_t Capacity = 32>
bool dspark::SpscQueue< T, Capacity >::empty ( ) const
inlinenoexcept

Returns true if the queue appears empty (approximate).

Definition at line 139 of file SpscQueue.h.

◆ operator=()

template<typename T , std::size_t Capacity = 32>
SpscQueue & dspark::SpscQueue< T, Capacity >::operator= ( const SpscQueue< T, Capacity > &  )
delete

◆ pop()

template<typename T , std::size_t Capacity = 32>
bool dspark::SpscQueue< T, Capacity >::pop ( T &  item)
inlinenoexcept

Pops an element from the queue (consumer side).

Parameters
[out]itemReceives the dequeued element if the queue is not empty.
Return values
trueif an element was dequeued.
falseif the queue was empty.
Note
Lock-free, wait-free, allocation-free. Safe to call from any single consumer thread.

Definition at line 107 of file SpscQueue.h.

◆ push()

template<typename T , std::size_t Capacity = 32>
bool dspark::SpscQueue< T, Capacity >::push ( const T &  item)
inlinenoexcept

Pushes an element into the queue (producer side).

Parameters
itemThe element to enqueue.
Return values
trueif the element was successfully enqueued.
falseif the queue is full (element dropped).
Note
Lock-free, wait-free, allocation-free. Safe to call from any single producer thread.

Definition at line 80 of file SpscQueue.h.

◆ sizeApprox()

template<typename T , std::size_t Capacity = 32>
std::size_t dspark::SpscQueue< T, Capacity >::sizeApprox ( ) const
inlinenoexcept

Returns the approximate number of elements in the queue.

Note
This is a snapshot and may be stale by the time you act on it. Use it only for diagnostics, never for control flow.
Returns
Number of elements currently enqueued.

Definition at line 131 of file SpscQueue.h.


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