RTOS Wrapper
API reference
Loading...
Searching...
No Matches
Classes | Namespaces
SeqlockSnapshot.h File Reference

Single-writer / many-reader coherent snapshot of a POD value. More...

#include <atomic>
#include <climits>
#include <cstddef>
#include <cstdint>
#include <cstring>
#include <type_traits>
#include "OsAbstraction.h"
#include "OsUtility.h"

Go to the source code of this file.

Classes

class  hf::SnapshotReader< T >
 
class  hf::SnapshotWriter< T >
 
class  hf::SeqlockSnapshot< T >
 

Namespaces

namespace  hf
 

Detailed Description

Single-writer / many-reader coherent snapshot of a POD value.

Three types in one header:

Algorithm
Writer: bumps seq_ to odd → memcpy T payload → bumps seq_ to even. Reader: snapshots seq_ → memcpy payload → re-reads seq_; retry while the start seq was odd or the two reads differ.
Thread-safety
  • Single writer assumed (Publish not safe to call concurrently from multiple writers; protect externally if ever needed).
  • Many readers — Read is wait-free in the absence of writes and bounded-retry under contention.
  • Optional waiter: backed by a lazily-created FreeRTOS event group; WaitForChange is task-context only.
Allocation
No heap allocation. Inline T storage; event group created on first WaitForChange / ClearWaitEvent use.
Constraints
T must be trivially copyable.