|
libxr
1.0
Want to be the best embedded framework
|
SPSC mailbox retaining only the latest fully published value. More...
#include <latest_snapshot.hpp>
Public Member Functions | |
| LatestSnapshot (const T &initial) noexcept(std::is_nothrow_copy_constructible_v< T >) | |
| void | Store (const T &value) noexcept(std::is_nothrow_copy_assignable_v< T >) |
| Publish one complete value. | |
| bool | LoadLatest (T &output) noexcept(std::is_nothrow_copy_assignable_v< T >) |
| Copy the latest complete value into output. | |
| LatestSnapshot (const LatestSnapshot &)=delete | |
| LatestSnapshot & | operator= (const LatestSnapshot &)=delete |
| LatestSnapshot (LatestSnapshot &&)=delete | |
| LatestSnapshot & | operator= (LatestSnapshot &&)=delete |
Static Private Member Functions | |
| static constexpr uint32_t | Pack (uint32_t index, bool has_new) |
| static constexpr uint32_t | Index (uint32_t state) |
| static constexpr bool | HasNew (uint32_t state) |
Private Attributes | |
| T | slots_ [3] |
| std::atomic< uint32_t > | state_ {Pack(1U, false)} |
| uint32_t | front_ = 0U |
| uint32_t | back_ = 2U |
Static Private Attributes | |
| static constexpr uint32_t | INDEX_MASK = 0x3U |
| static constexpr uint32_t | HAS_NEW_BIT = 1U << 2U |
SPSC mailbox retaining only the latest fully published value.
The producer owns one back slot, the consumer owns one front slot, and an atomic middle slot carries the latest completed publication. Repeated stores may overwrite an unconsumed middle value, but never the value currently being copied by the consumer.
| T | Copy-assignable snapshot type. |
Definition at line 24 of file latest_snapshot.hpp.
|
inlineexplicitnoexcept |
Construct all three slots with the same initial value.
Definition at line 33 of file latest_snapshot.hpp.
|
inlinestaticconstexprprivate |
Definition at line 96 of file latest_snapshot.hpp.
|
inlinestaticconstexprprivate |
Definition at line 94 of file latest_snapshot.hpp.
|
inlinenoexcept |
Copy the latest complete value into output.
Definition at line 59 of file latest_snapshot.hpp.
|
inlinestaticconstexprprivate |
Definition at line 89 of file latest_snapshot.hpp.
|
inlinenoexcept |
Publish one complete value.
The value is copied into the producer-owned back slot before that slot is released to the consumer as the newest middle slot.
Definition at line 45 of file latest_snapshot.hpp.
|
private |
Definition at line 101 of file latest_snapshot.hpp.
|
private |
Definition at line 100 of file latest_snapshot.hpp.
|
staticconstexprprivate |
Definition at line 87 of file latest_snapshot.hpp.
|
staticconstexprprivate |
Definition at line 86 of file latest_snapshot.hpp.
|
private |
Definition at line 98 of file latest_snapshot.hpp.
|
private |
Definition at line 99 of file latest_snapshot.hpp.