|
libxr
Embedded C++ framework for bare-metal, RTOS and Linux
|
只保留最新一份完整值的单生产者、单消费者邮箱 / Single-producer, single-consumer mailbox that keeps only the latest complete value More...
#include <latest_snapshot.hpp>
Public Member Functions | |
| LatestSnapshot (const T &initial) noexcept(std::is_nothrow_copy_constructible_v< T >) | |
| 用同一个初始值构造三个槽 / Construct all three slots with the same initial value | |
| 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 >) |
| 把最新的完整值拷入 output / Copy the latest complete value into output | |
| LatestSnapshot (const LatestSnapshot &)=delete | |
| 禁止拷贝构造 / Non-copyable | |
| LatestSnapshot & | operator= (const LatestSnapshot &)=delete |
| 禁止拷贝赋值 / Non-copy-assignable | |
| LatestSnapshot (LatestSnapshot &&)=delete | |
| 禁止移动构造 / Non-movable | |
| LatestSnapshot & | operator= (LatestSnapshot &&)=delete |
| 禁止移动赋值 / Non-move-assignable | |
只保留最新一份完整值的单生产者、单消费者邮箱 / Single-producer, single-consumer mailbox that keeps only the latest complete value
内部有三个槽:生产者独占后槽,消费者独占前槽,中间槽由一个原子状态 交给对方,承载最新一次完成的发布。连续的 Store() 可以覆盖消费者尚未 取走的中间值,但不会覆盖消费者正在拷贝的值。适用于只关心最新数据的 场合,例如在接收中断里保存最新的反馈帧,由控制线程读取。
The three slots are a back slot owned by the producer, a front slot owned by the consumer, and a middle slot handed over through one atomic state, which carries the latest completed publication. Repeated Store() calls may overwrite a middle value the consumer has not taken, but never the value the consumer is copying. It suits data of which only the latest value matters, such as the latest feedback frame stored in a receive interrupt and read by a control thread.
| T | 可拷贝构造、可拷贝赋值的值类型 / Copy-constructible, copy-assignable value type |
Definition at line 38 of file latest_snapshot.hpp.
|
inlineexplicitnoexcept |
用同一个初始值构造三个槽 / Construct all three slots with the same initial value
| initial | 初始值,LoadLatest() 在第一次 Store() 之前输出它 / Initial value, output by LoadLatest() before the first Store() |
Definition at line 53 of file latest_snapshot.hpp.
|
inlinenoexcept |
把最新的完整值拷入 output / Copy the latest complete value into output
有新的发布时先取得它;没有时 output 得到消费者上一次取得的值。只能 由唯一的消费者串行调用。
A newer publication is acquired first; without one, output receives the value the consumer acquired last. Only the single consumer may call it, one call at a time.
| output | 接收值的对象 / Object receiving the value |
Definition at line 92 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. Only the single producer may call it.
| value | 要发布的值 / Value to publish |
Definition at line 70 of file latest_snapshot.hpp.