DISTRHO Plugin Framework
|
#include <RingBuffer.hpp>
Public Attributes | |
uint32_t | size |
uint32_t | head |
uint32_t | tail |
uint32_t | wrtn |
bool | invalidateCommit |
uint8_t * | buf |
Base structure for all RingBuffer containers. This struct details the data model used in DPF's RingBuffer class.
DPF RingBuffer uses a struct just like this one to store positions, buffer data, size, etc. The RingBuffer itself takes ownership of this struct and uses it to store any needed data. This allows to dynamically change the way its ring buffer is allocated, simply by changing the template type. For example, RingBufferControl<HeapBuffer>
will create a ring buffer with heap memory, which can be of any size. In the same vein, RingBufferControl<SmallStackBuffer>
will create a ring buffer with stack memory, directly tied to the RingBufferControl it belongs to.
The main idea behind this model is to allow RingBufferControl over memory created elsewhere, for example shared memory area. One can create/place the Buffer struct in shared memory, and point RingBufferControl to it, thus avoiding the pitfalls of sharing access to a non trivially-copyable/POD C++ class.
Unlike other ring buffers, an extra variable is used to track pending writes. This is so we can write a few bytes at a time and later mark the whole operation as complete, thus avoiding the issue of reading data too early from the other side. For example, write the size of some data first, and then the actual data. The reading side will only see data available once size + data is completely written and "committed".
uint32_t HeapBuffer::size |
Size of the buffer, allocated in buf. If the size is fixed (stack buffer), this variable can be static.
uint32_t HeapBuffer::head |
Current writing position, headmost position of the buffer. Increments when writing.
uint32_t HeapBuffer::tail |
Current reading position, last used position of the buffer. Increments when reading. head == tail means empty buffer.
uint32_t HeapBuffer::wrtn |
Temporary position of head until a commitWrite() is called. If buffer writing fails, wrtn will be back to head position thus ignoring the last operation(s). If buffer writing succeeds, head will be set to this variable.
bool HeapBuffer::invalidateCommit |
Boolean used to check if a write operation failed. This ensures we don't get incomplete writes.
uint8_t* HeapBuffer::buf |
Pointer to buffer data. This can be either stack or heap data, depending on the usecase.