Go to the documentation of this file.
55 #include <type_traits>
57 #include <SimoxUtility/threads/system_thread_id.h>
74 #define DEBUG_MODE_PRINT \
75 if (debugMode.load()) \
76 std::cout << '[' << simox::system_thread_id() << "] [" << this << "] "
85 template <
class... Ts>
145 uint_fast8_t flagsNow(
flags.load(std::memory_order_consume));
153 while (!
flags.compare_exchange_weak(flagsNow,
155 std::memory_order_release,
156 std::memory_order_consume))
169 template <
class U = T>
189 std::cout <<
'[' << simox::system_thread_id() <<
"] [0x" <<
this
190 <<
"] set debug mode to " << mode <<
'\n';
194 #undef DEBUG_MODE_PRINT
229 uint_fast8_t flagsNow(
flags.load(std::memory_order_consume));
230 while (!
flags.compare_exchange_weak(flagsNow,
232 std::memory_order_release,
233 std::memory_order_consume))
311 template <
typename T>
341 return tripleBuffer.getReadBuffer();
348 return tripleBuffer.getUpToDateReadBuffer();
355 return tripleBuffer._getNonConstReadBuffer();
362 return tripleBuffer._getNonConstHiddenBuffer();
369 return tripleBuffer.getReadBuffer();
379 return tripleBuffer.updateReadBuffer();
385 tripleBuffer.getWriteBuffer() = writeBuffer;
386 tripleBuffer.commitWrite();
393 tripleBuffer.reinitAllBuffers(init);
399 tripleBuffer.setDebugMode(mode);
static uint_fast8_t flagSwapWriteWithHidden(uint_fast8_t flags)
swap write and hidden indexes of given flags (set dirty to 1)
uint_fast8_t getWriteBufferIndex() const
static const uint_fast8_t writeBufferIndexShift
static const uint_fast8_t readBufferIndexShift
static const uint_fast8_t writeBufferIndexMask
uint_fast8_t getHiddenBufferIndex() const
WriteBufferedTripleBuffer(const T &init)
static const uint_fast8_t initialFlags
T & _getNonConstHiddenBuffer()
bool hasNewWrite(uint_fast8_t flags) const
bool updateReadBuffer() const
Swaps in the hidden buffer if it contains new data.
uint_fast8_t getReadBufferIndex() const
static const uint_fast8_t dirtyBitShift
const T & getWriteBuffer() const
void setDebugMode(bool mode)
void setDebugMode(bool mode)
T & _getNonConstHiddenWriteBuffer()
static const uint_fast8_t hiddenToReadShift
std::shared_ptr< Value > value()
void reinitAllBuffers(T &&writeBuff, T &&hiddenBuff, T &&readBuff)
WriteBufferedTripleBuffer()
T & _getNonConstReadBuffer()
std::atomic_uint_fast8_t flags
const T & getReadBuffer() const
static uint_fast8_t flagSwapReadWithHidden(uint_fast8_t flags)
swap read and hidden indexes
TripleBuffer(T &&initR, T &&initH, T &&initW)
const T & getWriteBuffer() const
static const uint_fast8_t hiddenBufferIndexMask
static const uint_fast8_t dirtyBitMask
void reinitAllBuffers(const T &init)
static const uint_fast8_t hiddenToWriteShift
TripleBuffer(const Ts &... ts)
std::atomic_bool debugMode
static const uint_fast8_t hiddenBufferIndexShift
Same as the TripleBuffer, but partial writes of the data structure are ok. The write operation may be...
TripleBuffer & operator=(const TripleBuffer &)=delete
const T & getReadBuffer() const
T & _getNonConstReadBuffer()
const T & getUpToDateReadBuffer() const
const T & getUpToDateReadBuffer() const
T & _getNonConstHiddenBuffer()
std::enable_if< std::is_copy_constructible< U >::value >::type reinitAllBuffers(const T &init)
void swapWriteAndHiddenBuffer()
Swap the write buffer with the hidden buffer.
static const uint_fast8_t readBufferIndexMask
This file offers overloads of toIce() and fromIce() functions for STL container types.
bool updateReadBuffer() const
Swaps in the hidden buffer if it contains new data.
A simple triple buffer for lockfree comunication between a single writer and a single reader.