|
A simple triple buffer for lockfree comunication between a single writer and a single reader. More...
#include <ArmarXCore/util/CPPUtility/TripleBuffer.h>
Public Member Functions | |
T & | _getNonConstHiddenBuffer () |
T & | _getNonConstReadBuffer () |
void | commitWrite () |
const T & | getReadBuffer () const |
const T & | getUpToDateReadBuffer () const |
T & | getWriteBuffer () |
const T & | getWriteBuffer () const |
template<class U = T> | |
std::enable_if< std::is_copy_constructible< U >::value >::type | reinitAllBuffers (const T &init) |
void | reinitAllBuffers (T &&writeBuff, T &&hiddenBuff, T &&readBuff) |
void | setDebugMode (bool mode) |
template<class... Ts> | |
TripleBuffer (const Ts &...ts) | |
TripleBuffer (T &&initR, T &&initH, T &&initW) | |
bool | updateReadBuffer () const |
Swaps in the hidden buffer if it contains new data. More... | |
Protected Member Functions | |
uint_fast8_t | getHiddenBufferIndex () const |
uint_fast8_t | getReadBufferIndex () const |
uint_fast8_t | getWriteBufferIndex () const |
bool | hasNewWrite (uint_fast8_t flags) const |
TripleBuffer & | operator= (const TripleBuffer &)=delete |
void | swapWriteAndHiddenBuffer () |
Swap the write buffer with the hidden buffer. More... | |
TripleBuffer (const TripleBuffer &)=delete | |
Static Protected Member Functions | |
static uint_fast8_t | flagSwapReadWithHidden (uint_fast8_t flags) |
swap read and hidden indexes More... | |
static uint_fast8_t | flagSwapWriteWithHidden (uint_fast8_t flags) |
swap write and hidden indexes of given flags (set dirty to 1) More... | |
Protected Attributes | |
T | buffer [3] |
std::atomic_bool | debugMode {false} |
std::atomic_uint_fast8_t | flags {initialFlags} |
Static Protected Attributes | |
static const uint_fast8_t | dirtyBitMask = 1 << dirtyBitShift |
static const uint_fast8_t | dirtyBitShift = 7 |
static const uint_fast8_t | hiddenBufferIndexMask = 3 << hiddenBufferIndexShift |
static const uint_fast8_t | hiddenBufferIndexShift = 2 |
static const uint_fast8_t | hiddenToReadShift = hiddenBufferIndexShift - readBufferIndexShift |
static const uint_fast8_t | hiddenToWriteShift = writeBufferIndexShift - hiddenBufferIndexShift |
static const uint_fast8_t | initialFlags = 2 + (1 << 2) |
static const uint_fast8_t | readBufferIndexMask = 3 << readBufferIndexShift |
static const uint_fast8_t | readBufferIndexShift = 0 |
static const uint_fast8_t | writeBufferIndexMask = 3 << writeBufferIndexShift |
static const uint_fast8_t | writeBufferIndexShift = 4 |
A simple triple buffer for lockfree comunication between a single writer and a single reader.
If more than one reader/writer is required, you have to synchronize the access. Writers must not have: writes to the same data cell (except it is an atomic et al) and no writes are allowed during swapping of the buffer. Readers must not read when the buffer is swapped. If a writer only writes parts of the data structure, data loss could occure! (use a WriteBufferedTripleBuffer instead)
Definition at line 71 of file TripleBuffer.h.
|
inline |
Definition at line 78 of file TripleBuffer.h.
|
inline |
Definition at line 85 of file TripleBuffer.h.
|
protecteddelete |
|
inline |
Definition at line 121 of file TripleBuffer.h.
|
inline |
Definition at line 115 of file TripleBuffer.h.
|
inline |
Definition at line 146 of file TripleBuffer.h.
|
inlinestaticprotected |
swap read and hidden indexes
swap read and hidden indexes of given flags (set dirty to 0)
flags | the current flags |
Definition at line 216 of file TripleBuffer.h.
|
inlinestaticprotected |
swap write and hidden indexes of given flags (set dirty to 1)
flags | the current flags |
Definition at line 229 of file TripleBuffer.h.
|
inlineprotected |
|
inline |
Definition at line 102 of file TripleBuffer.h.
|
inlineprotected |
|
inline |
Definition at line 108 of file TripleBuffer.h.
|
inline |
Definition at line 90 of file TripleBuffer.h.
|
inline |
Definition at line 96 of file TripleBuffer.h.
|
inlineprotected |
|
inlineprotected |
|
protecteddelete |
|
inline |
Definition at line 159 of file TripleBuffer.h.
|
inline |
Definition at line 165 of file TripleBuffer.h.
|
inlineprotected |
Swap the write buffer with the hidden buffer.
Definition at line 196 of file TripleBuffer.h.
|
inline |
Swaps in the hidden buffer if it contains new data.
Definition at line 131 of file TripleBuffer.h.
|
protected |
Definition at line 257 of file TripleBuffer.h.
|
protected |
Definition at line 258 of file TripleBuffer.h.
|
staticprotected |
Definition at line 250 of file TripleBuffer.h.
|
staticprotected |
Definition at line 242 of file TripleBuffer.h.
|
mutableprotected |
Definition at line 256 of file TripleBuffer.h.
|
staticprotected |
Definition at line 248 of file TripleBuffer.h.
|
staticprotected |
Definition at line 240 of file TripleBuffer.h.
|
staticprotected |
Definition at line 244 of file TripleBuffer.h.
|
staticprotected |
Definition at line 245 of file TripleBuffer.h.
|
staticprotected |
Definition at line 252 of file TripleBuffer.h.
|
staticprotected |
Definition at line 247 of file TripleBuffer.h.
|
staticprotected |
Definition at line 239 of file TripleBuffer.h.
|
staticprotected |
Definition at line 249 of file TripleBuffer.h.
|
staticprotected |
Definition at line 241 of file TripleBuffer.h.