|
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 39 of file ring_buffer.h.
|
inlineexplicit |
Definition at line 42 of file ring_buffer.h.
|
inline |
Definition at line 48 of file ring_buffer.h.
|
inline |
Definition at line 288 of file ring_buffer.h.
|
inline |
Definition at line 258 of file ring_buffer.h.
|
inline |
Definition at line 111 of file ring_buffer.h.
|
inline |
Definition at line 148 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 208 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 236 of file ring_buffer.h.
|
inline |
Definition at line 184 of file ring_buffer.h.
|
inline |
Definition at line 290 of file ring_buffer.h.
|
inline |
Definition at line 274 of file ring_buffer.h.
|
inline |
Definition at line 252 of file ring_buffer.h.
|
inline |
Definition at line 168 of file ring_buffer.h.
|
inline |
Definition at line 98 of file ring_buffer.h.
|
inline |
Definition at line 128 of file ring_buffer.h.
|
inline |
Definition at line 260 of file ring_buffer.h.