pub struct RingLayout {
pub slot_count: u32,
pub slot_bytes: u32,
}Expand description
Memory layout of a single-writer, many-reader frame ring.
Layout (all integers little-endian):
[ ring header ] HEADER_LEN bytes: magic, version, slot_count, slot_bytes
[ slot 0 ] SLOT_HEADER_LEN + slot_bytes + SLOT_TRAILER_LEN
[ slot 1 ]
...Each slot is seq_begin:u64 | byte_len:u32 | _pad:u32 | <slot_bytes data> | seq_end:u64.
The writer stores seq_begin, then the data and length, then seq_end; a
reader loads seq_end, copies the data, then re-checks seq_begin and
seq_end against the descriptor’s seq. If either differs the read was torn
by a slot recycle and is discarded. Sizing slot_count above the number of
concurrent consumers plus their read latency makes torn reads rare.
Fields§
§slot_count: u32§slot_bytes: u32Capacity of one slot’s pixel region (the largest frame the ring holds).
Implementations§
Source§impl RingLayout
impl RingLayout
pub const VERSION: u16 = 1
pub const HEADER_LEN: usize = 16
Sourcepub const SLOT_HEADER_LEN: usize = 16
pub const SLOT_HEADER_LEN: usize = 16
seq_begin (u64) + byte_len (u32) + pad (u32).
Sourcepub const SLOT_TRAILER_LEN: usize = 8
pub const SLOT_TRAILER_LEN: usize = 8
seq_end (u64).
Sourcepub fn for_frame(
slot_count: u32,
width: u32,
height: u32,
format: FrameFormat,
) -> Self
pub fn for_frame( slot_count: u32, width: u32, height: u32, format: FrameFormat, ) -> Self
Size a ring that holds frames up to width x height in format.
pub fn slot_stride(&self) -> usize
Sourcepub fn validate(&self) -> Result<(), RingError>
pub fn validate(&self) -> Result<(), RingError>
Validate the layout against the on-disk header’s field widths. The
header stores slot_count in two bytes, so a layout above
MAX_SLOT_COUNT would truncate on write and the reader’s
header-derived layout would name a different slot than the writer used.
Callers validate at ring-creation / engine startup so a misconfigured
depth is rejected loudly rather than silently truncated.
Sourcepub fn write_header(&self, region: &mut [u8]) -> Result<(), RingError>
pub fn write_header(&self, region: &mut [u8]) -> Result<(), RingError>
Write the ring header at the front of a freshly created region. Rejects a
slot_count the two-byte header field cannot represent so the writer’s
slot math (seq % slot_count) can never diverge from a reader that
re-derives the layout from the header.
Sourcepub fn read_header(region: &[u8]) -> Option<RingLayout>
pub fn read_header(region: &[u8]) -> Option<RingLayout>
Read the layout a writer recorded in a region’s header.
Trait Implementations§
Source§impl Clone for RingLayout
impl Clone for RingLayout
impl Copy for RingLayout
Source§impl Debug for RingLayout
impl Debug for RingLayout
impl Eq for RingLayout
Source§impl PartialEq for RingLayout
impl PartialEq for RingLayout
impl StructuralPartialEq for RingLayout
Auto Trait Implementations§
impl Freeze for RingLayout
impl RefUnwindSafe for RingLayout
impl Send for RingLayout
impl Sync for RingLayout
impl Unpin for RingLayout
impl UnsafeUnpin for RingLayout
impl UnwindSafe for RingLayout
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.