Class thl::TripleBuffer#
-
template<typename T>
class TripleBuffer# Wait-free single-producer, single-consumer “latest value” mailbox.
The reader always gets the most recent complete value; values it did not pick up are overwritten. Exactly one writer thread and one reader thread, which may be the same. T must be trivially copyable.
The three slots and the two sides’ indices each start a cache line of their own (core::k_cache_line_size), so a TripleBuffer is at least six of them.
Public Functions
-
TripleBuffer() = default#
-
TripleBuffer(const TripleBuffer&) = delete#
-
TripleBuffer &operator=(const TripleBuffer&) = delete#
-
TripleBuffer(TripleBuffer&&) = delete#
-
TripleBuffer &operator=(TripleBuffer&&) = delete#
-
~TripleBuffer() = default#
-
inline T &write_buffer() noexcept#
The writer’s slot, to fill in place before publish().
Its content is a stale value from some earlier publication, not the last one written.
-
inline void publish() noexcept#
Publish write_buffer().
-
inline bool has_new() const noexcept#
True if a value was published that neither read() nor update() has taken yet (a hint: the writer may publish right after).
-
inline bool read(T &out) noexcept#
Copy the latest value into
outif one was published since the last read().Returns false (and leaves
outuntouched) otherwise.
-
TripleBuffer() = default#