|
MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
|
Lock-free cell holding one immutable snapshot of a value, read without blocking. More...
#include <SnapshotCell.hpp>
Classes | |
| class | Guard |
| Keeps one snapshot alive and unchanged while it exists. More... | |
Public Member Functions | |
| SnapshotCell & | operator= (const SnapshotCell &)=delete |
| SnapshotCell & | operator= (SnapshotCell &&)=delete |
| void | publish (T value) |
Replaces the snapshot with value, whatever it was. | |
| Guard | read () const noexcept |
| Pins the current snapshot. | |
| void | reset () |
| Empties the cell. | |
| SnapshotCell () noexcept=default | |
| Creates an empty cell. | |
| SnapshotCell (const SnapshotCell &)=delete | |
| SnapshotCell (SnapshotCell &&)=delete | |
| SnapshotCell (T initial) | |
Creates a cell already holding initial. | |
| template<typename Edit> requires std::invocable<Edit&, T&> && std::default_initializable<T> && std::copy_constructible<T> | |
| bool | update (Edit edit) |
| Edits a copy of the current snapshot and publishes it. | |
| ~SnapshotCell () | |
| Frees the current snapshot and every retired one. | |
Private Member Functions | |
| void | reclaim () |
| void | replace (const T *next) |
| void | retire (const T *old) |
Private Attributes | |
| std::atomic< const T * > | m_head { nullptr } |
| std::atomic< uint32_t > | m_readers { 0 } |
| SweepList< std::unique_ptr< const T > > | m_retired |
Lock-free cell holding one immutable snapshot of a value, read without blocking.
read() returns a Guard on the snapshot that was current at that moment. It stays valid and unchanged while the Guard lives, whatever writers publish meanwhile. update() copies the current snapshot, edits the copy and swaps it in, retrying when another writer got there first. publish() and reset() replace it unconditionally.
Replaced snapshots are freed by a later writer once no Guard is held, so a Guard kept for long delays freeing. Hold a Guard for the lookup only, and never past the cell's lifetime.
Suited to values read often and replaced rarely, since every update copies the whole value.
| T | Snapshot type. Readers see it as const, so it needs no internal synchronisation. update() needs it default constructible and copyable. |
Definition at line 38 of file SnapshotCell.hpp.