loon
High-performance header-only C++ library for low-latency applications
Loading...
Searching...
No Matches
loon::SpscQueue< T, N > Class Template Reference

A lock-free single-producer single-consumer (SPSC) queue with fixed capacity. More...

#include <spsc.hpp>

Public Member Functions

size_t capacity () const
 Returns the maximum number of elements the queue can hold.
 
bool empty () const
 Checks if the queue is empty.
 
bool full () const
 Checks if the queue is full.
 

Detailed Description

template<typename T, size_t N>
class loon::SpscQueue< T, N >

A lock-free single-producer single-consumer (SPSC) queue with fixed capacity.

SpscQueue provides O(1) push and pop operations without locks, suitable for communication between a single producer thread and a single consumer thread. The capacity is fixed at compile time and the queue will reject new elements when full.

Definition at line 12 of file spsc.hpp.

Member Function Documentation

◆ capacity()

template<typename T , size_t N>
size_t loon::SpscQueue< T, N >::capacity ( ) const
inline

Returns the maximum number of elements the queue can hold.

Returns
The maximum number of elements the queue can hold. The actual buffer size is N+1, but the usable capacity is N.
Examples
/home/runner/work/loon/loon/include/loon/spsc.hpp.

Definition at line 63 of file spsc.hpp.

◆ empty()

template<typename T , size_t N>
bool loon::SpscQueue< T, N >::empty ( ) const
inline

Checks if the queue is empty.

Returns
true if the queue is empty, false otherwise.
Examples
/home/runner/work/loon/loon/include/loon/spsc.hpp.

Definition at line 67 of file spsc.hpp.

◆ full()

template<typename T , size_t N>
bool loon::SpscQueue< T, N >::full ( ) const
inline

Checks if the queue is full.

Returns
true if the queue is full, false otherwise.
Examples
/home/runner/work/loon/loon/include/loon/spsc.hpp.

Definition at line 71 of file spsc.hpp.


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