|
Zrythm v2.0.0-DEV
a highly automated and intuitive digital audio workstation
|
A ring buffer implementation for storing elements of type T. More...
#include <src/utils/ring_buffer.h>
Public Member Functions | |
| RingBuffer (size_t size) | |
| RingBuffer (const RingBuffer &other) | |
| bool | write (const T &src) |
| void | force_write (const T &src) |
| bool | write_multiple (const T *src, size_t count) |
| void | force_write_multiple (const T *src, size_t count) |
| bool | skip (size_t num_elements) |
| bool | read (T &dst) |
| bool | peek (T &dst) const |
| Peek a single element from the ring buffer without moving the read head. | |
| size_t | peek_multiple (T *dst, size_t count) const |
| Peek multiple elements from the ring buffer without moving the read head. | |
| void | reset () |
| size_t | capacity () const |
| size_t | write_space () const |
| size_t | read_space () const |
| bool | can_read_multiple (size_t count) const |
| bool | read_multiple (T *dst, size_t count) |
A ring buffer implementation for storing elements of type T.
The RingBuffer class provides a thread-safe, fixed-size buffer that allows for efficient reading and writing of elements. It uses atomic operations to ensure thread safety.
The buffer has a fixed capacity, which is one more than the size specified in the constructor. This extra slot is used to differentiate between a full and an empty buffer.
The write and read functions return true if the operation was successful, and false otherwise (e.g., if the buffer is full or empty, respectively).
The reset function can be used to reset the read and write heads to the beginning of the buffer.
The capacity, write_space, and read_space functions can be used to query the current state of the buffer.
Definition at line 38 of file ring_buffer.h.
|
inlineexplicit |
Definition at line 41 of file ring_buffer.h.
|
inline |
Definition at line 47 of file ring_buffer.h.
|
inline |
Definition at line 287 of file ring_buffer.h.
|
inline |
Definition at line 257 of file ring_buffer.h.
|
inline |
Definition at line 110 of file ring_buffer.h.
|
inline |
Definition at line 147 of file ring_buffer.h.
|
inline |
Peek a single element from the ring buffer without moving the read head.
This function attempts to peek the next element from the current read position without modifying the state of the buffer.
| [out] | dst | Reference to the variable where the peeked element will be stored. |
Definition at line 207 of file ring_buffer.h.
|
inline |
Peek multiple elements from the ring buffer without moving the read head.
This function attempts to peek up to the requested number of elements from the ring buffer, starting from the current read position. It does not modify the state of the buffer.
| [out] | dst | Pointer to the destination array where peeked elements will be stored. |
| [in] | count | Maximum number of elements to peek. |
Definition at line 235 of file ring_buffer.h.
|
inline |
Definition at line 183 of file ring_buffer.h.
|
inline |
Definition at line 289 of file ring_buffer.h.
|
inline |
Definition at line 273 of file ring_buffer.h.
|
inline |
Definition at line 251 of file ring_buffer.h.
|
inline |
Definition at line 167 of file ring_buffer.h.
|
inline |
Definition at line 97 of file ring_buffer.h.
|
inline |
Definition at line 127 of file ring_buffer.h.
|
inline |
Definition at line 259 of file ring_buffer.h.