qb
2.0.0.0
C++17 Actor Framework
|
Base implementation of the Single-Producer Single-Consumer ringbuffer. More...
#include <spsc.h>
Public Member Functions | |
bool | empty () |
Check if the buffer is empty. | |
Public Member Functions inherited from qb::nocopy | |
nocopy ()=default | |
Default constructor. | |
nocopy (nocopy const &)=delete | |
Deleted copy constructor. | |
nocopy (nocopy const &&)=delete | |
Deleted move constructor. | |
nocopy & | operator= (nocopy const &)=delete |
Deleted copy assignment operator. | |
nocopy & | operator= (nocopy &&)=delete |
Deleted move assignment operator. |
Protected Member Functions | |
ringbuffer () | |
Default constructor initializing indices. | |
size_t | read_available (size_t const max_size) const |
Get the number of elements available for reading. | |
size_t | write_available (size_t const max_size) const |
Get the number of slots available for writing. | |
bool | enqueue (T const &t, T *buffer, size_t const max_size) |
Enqueue a single element into the buffer. | |
template<bool _All> | |
size_t | enqueue (const T *input_buffer, size_t input_count, T *internal_buffer, size_t const max_size) |
Enqueue multiple elements into the buffer. | |
size_t | dequeue (T *output_buffer, size_t output_count, T *internal_buffer, size_t const max_size) |
Dequeue multiple elements from the buffer. | |
template<typename _Func> | |
size_t | consume_all (_Func const &functor, T *internal_buffer, size_t max_size) |
Process all available elements in the buffer using a functor. | |
const T & | front (const T *internal_buffer) const |
Get a reference to the element at the read index (const version) | |
T & | front (T *internal_buffer) |
Get a reference to the element at the read index. |
Static Protected Member Functions | |
static size_t | next_index (size_t arg, size_t const max_size) |
Calculate the next index in the buffer with wrap-around handling. | |
static size_t | read_available (size_t write_index, size_t read_index, size_t const max_size) |
Calculate how many elements are available for reading. | |
static size_t | write_available (size_t write_index, size_t read_index, size_t const max_size) |
Calculate how many elements can be written. |
Base implementation of the Single-Producer Single-Consumer ringbuffer.
This class provides the core functionality for SPSC ringbuffers, handling the read and write index management and the memory operations required for enqueueing and dequeueing elements.
T | Type of elements stored in the ringbuffer |
|
inlinestaticprotected |
Calculate the next index in the buffer with wrap-around handling.
arg | Current index |
max_size | Maximum size of the buffer |
|
inlinestaticprotected |
Calculate how many elements are available for reading.
write_index | Current write index |
read_index | Current read index |
max_size | Maximum size of the buffer |
|
inlinestaticprotected |
Calculate how many elements can be written.
write_index | Current write index |
read_index | Current read index |
max_size | Maximum size of the buffer |
|
inlinenodiscardprotected |
Get the number of elements available for reading.
max_size | Maximum size of the buffer |
|
inlinenodiscardprotected |
Get the number of slots available for writing.
max_size | Maximum size of the buffer |
|
inlineprotected |
Enqueue a single element into the buffer.
t | Element to enqueue |
buffer | Pointer to the internal buffer |
max_size | Maximum size of the buffer |
|
inlineprotected |
Enqueue multiple elements into the buffer.
_All | If true, either all elements are enqueued or none |
input_buffer | Pointer to source elements |
input_count | Number of elements to enqueue |
internal_buffer | Pointer to the internal buffer |
max_size | Maximum size of the buffer |
|
inlineprotected |
Dequeue multiple elements from the buffer.
output_buffer | Destination buffer for dequeued elements |
output_count | Maximum number of elements to dequeue |
internal_buffer | Pointer to the internal buffer |
max_size | Maximum size of the buffer |
|
inlineprotected |
Process all available elements in the buffer using a functor.
_Func | Functor type |
functor | Function to call for each batch of elements |
internal_buffer | Pointer to the internal buffer |
max_size | Maximum size of the buffer |
|
inlineprotected |
Get a reference to the element at the read index (const version)
internal_buffer | Pointer to the internal buffer |
|
inlineprotected |
Get a reference to the element at the read index.
internal_buffer | Pointer to the internal buffer |
|
inline |
Check if the buffer is empty.