TINC
Toolkit for Interactive Computation
|
#include <BufferManager.hpp>
Public Member Functions | |
BufferManager (uint16_t size=2) | |
std::shared_ptr< DataType > | get (bool markAsUsed=true) |
Get current buffer for reading. More... | |
std::shared_ptr< DataType > | get (bool *isNew) |
Get current buffer for reading checking if data is new. More... | |
std::shared_ptr< DataType > | getWritable () |
Get a pointer to a writable buffer. More... | |
void | doneWriting (std::shared_ptr< DataType > buffer) |
Mark a buffer as ready to read. More... | |
bool | newDataAvailable () |
Check if there are buffers that have been written but not read. More... | |
Public Attributes | |
const int | mSize |
Protected Attributes | |
std::vector< std::shared_ptr< DataType > > | mData |
std::mutex | mDataLock |
bool | mNewData {false} |
uint16_t | mReadBuffer {0} |
uint16_t | mWriteBuffer {1} |
The BufferManager class provides a thread safe memory buffer that can do fast reads as it requires only a pointer swap. It provides double buffering by default, but it allows for a larger number of write buffers in cases where concurrent writes would otherwise block the other writes.
Definition at line 48 of file BufferManager.hpp.
|
inline |
Definition at line 52 of file BufferManager.hpp.
|
inline |
Mark a buffer as ready to read.
buffer | The buffer previously received from getWritable() |
The buffer provided must come from getWritable() otherwise behavior is undefined.
Definition at line 114 of file BufferManager.hpp.
|
inline |
Get current buffer for reading checking if data is new.
isNew | this is set to true if data returned is "new", false otherwise |
Definition at line 76 of file BufferManager.hpp.
|
inline |
Get current buffer for reading.
markAsUsed | if false, the returned buffer keeps its "new" status |
Definition at line 63 of file BufferManager.hpp.
|
inline |
Get a pointer to a writable buffer.
When done writing this buffer, call doneWriting()
Definition at line 92 of file BufferManager.hpp.
|
inline |
Check if there are buffers that have been written but not read.
Definition at line 124 of file BufferManager.hpp.
|
protected |
Definition at line 130 of file BufferManager.hpp.
|
protected |
Definition at line 132 of file BufferManager.hpp.
|
protected |
Definition at line 133 of file BufferManager.hpp.
|
protected |
Definition at line 134 of file BufferManager.hpp.
const int tinc::BufferManager< DataType >::mSize |
Definition at line 50 of file BufferManager.hpp.
|
protected |
Definition at line 135 of file BufferManager.hpp.