Struct Snapshot Mailbox
pub struct SnapshotMailbox<const N: usize> { /* private fields */ }Expand description
Fixed-size, allocation-free coherent snapshots with bounded attempts.
Available on targets with 64-bit atomics. The generation must not wrap during a single read or between reading a snapshot and publishing conditionally. Atomic words and sequential consistency avoid unsynchronized shared storage. Successful writers hold a sequence reservation for N stores, without waiting on readers. A preempted writer makes reads unavailable until it completes; callers must never spin in an audio callback waiting for a snapshot.
use ravet_foundation::{SnapshotMailbox, PublishError};
let mailbox = SnapshotMailbox::new([1.0_f32.to_bits(), 0]);
let before = mailbox.try_read().unwrap();
mailbox.try_publish([0.5_f32.to_bits(), 1]).unwrap();
assert_eq!(mailbox.try_publish_if(before.generation, before.words), Err(PublishError::Stale));
assert_eq!(f32::from_bits(mailbox.try_read().unwrap().words[0]), 0.5);Implementations§
§impl<const N: usize> SnapshotMailbox<N>
impl<const N: usize> SnapshotMailbox<N>
pub fn new(words: [u32; N]) -> Self
pub fn try_read(&self) -> Option<WordSnapshot<N>>
pub fn try_read(&self) -> Option<WordSnapshot<N>>
Return one coherent snapshot or None when a publication overlaps it.
pub fn try_publish(&self, words: [u32; N]) -> Result<u64, PublishError>
pub fn try_publish(&self, words: [u32; N]) -> Result<u64, PublishError>
Publish a complete snapshot, failing immediately if a writer overlaps.
pub fn try_publish_if(
&self,
expected: u64,
words: [u32; N],
) -> Result<u64, PublishError>
pub fn try_publish_if( &self, expected: u64, words: [u32; N], ) -> Result<u64, PublishError>
Publish only if no newer snapshot has superseded the caller’s generation. Audio-side reflection uses this to avoid overwriting a concurrent restore.