Go to the documentation of this file.
54 #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 << "] "
133 uint_fast8_t flagsNow(
flags.load(std::memory_order_consume));
141 while (!
flags.compare_exchange_weak(flagsNow,
flagSwapReadWithHidden(flagsNow), std::memory_order_release, std::memory_order_consume));
152 template<
class U = T>
167 std::cout <<
'[' << simox::system_thread_id() <<
"] [0x" <<
this
168 <<
"] set debug mode to " << mode <<
'\n';
172 #undef DEBUG_MODE_PRINT
198 uint_fast8_t flagsNow(
flags.load(std::memory_order_consume));
199 while (!
flags.compare_exchange_weak(flagsNow,
flagSwapWriteWithHidden(flagsNow), std::memory_order_release, std::memory_order_consume));
266 template <
typename T>
293 return tripleBuffer.getReadBuffer();
298 return tripleBuffer.getUpToDateReadBuffer();
304 return tripleBuffer._getNonConstReadBuffer();
309 return tripleBuffer._getNonConstHiddenBuffer();
314 return tripleBuffer.getReadBuffer();
323 return tripleBuffer.updateReadBuffer();
328 tripleBuffer.getWriteBuffer() = writeBuffer;
329 tripleBuffer.commitWrite();
335 tripleBuffer.reinitAllBuffers(init);
340 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
TripleBuffer(const Ts &...ts)
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
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.