This template class wraps the Jack lock-free ringbuffer. More...
#include <jackringbuffer.hpp>
Public Member Functions | |
RingBuffer (size_t size, bool mlock=false) | |
The Constructor. | |
~RingBuffer () | |
The Destructor. | |
size_t | length () |
Get the total length of the ring buffer. | |
size_t | getReadSpace () |
Get the number of items that can be read at this time. | |
size_t | getWriteSpace () |
Get the number of items that can be written at this time. | |
void | read (Type &dest) |
Read into dest. | |
void | read (Type *dest, unsigned cnt) |
Read into an array. | |
void | write (Type src) |
Write into the ring buffer. | |
void | write (Type *src, unsigned int cnt) |
Write an array of values into the ring buffer. | |
void | reset () |
Reset. |
This template class wraps the Jack lock-free ringbuffer.
This class creates a lock-free ring buffer that accepts a specific data type.
The key attribute of a ringbuffer is that it can be safely accessed by two threads simultaneously -- one reading from the buffer and the other writing to it -- without using any synchronization or mutual exclusion primitives. For this to work correctly, there can only be a single reader and a single writer thread. Their identities cannot be interchanged.
JackCpp::RingBuffer< Type >::RingBuffer | ( | size_t | size, | |
bool | mlock = false | |||
) | [inline] |
The Constructor.
size | the number of items that the ring buffer should be able to hold | |
mlock | a boolean indicating whether or not the ring buffer should be locked in memory |
void JackCpp::RingBuffer< Type >::read | ( | Type & | dest | ) | [inline] |
Read into dest.
Read from the buffer into a variable.
dest | an item to be read into |
void JackCpp::RingBuffer< Type >::read | ( | Type * | dest, | |
unsigned | cnt | |||
) | [inline] |
Read into an array.
Read from the buffer into an array.
dest | an array to be read into | |
cnt | the number of elements to read into this array |
void JackCpp::RingBuffer< Type >::reset | ( | ) | [inline] |
Reset.
This is not threadsafe. This resets the read and write pointers, effectively making the ring buffer empty.
void JackCpp::RingBuffer< Type >::write | ( | Type * | src, | |
unsigned int | cnt | |||
) | [inline] |
Write an array of values into the ring buffer.
src | an array of values to write | |
cnt | the number of items from the array to write into our buffer |
void JackCpp::RingBuffer< Type >::write | ( | Type | src | ) | [inline] |
Write into the ring buffer.
src | the value to write |