Skip to main content

SpscRingCore

Struct SpscRingCore 

Source
pub struct SpscRingCore { /* private fields */ }
Expand description

Lamport SPSC ring core. Used as the storage backing SharedRingSpsc; applications normally reach for the typed Producer / Consumer halves rather than this raw core.

Implementations§

Source§

impl SpscRingCore

Source

pub fn create_anon(capacity: usize) -> Result<Self, RingError>

Anonymous in-memory ring (in-process only). Fastest construction; skips file create + ftruncate + first-page-fault.

Source

pub fn create( path: impl AsRef<Path>, capacity: usize, ) -> Result<Self, RingError>

File-backed ring; cross-process visibility via the OS page cache. Obtains the ring at path: initializes an empty one if the path does not yet exist and attaches to it if it does. Attaching leaves queued items and both cursors in place; a ring built with a different capacity is a LayoutMismatch. reset reinitializes.

Source

pub fn reset(path: impl AsRef<Path>, capacity: usize) -> Result<Self, RingError>

Truncate the ring at path and initialize an empty one, discarding queued items live peers hold. For a caller that knows it owns the path.

Source

pub fn open( path: impl AsRef<Path>, expected_capacity: usize, ) -> Result<Self, RingError>

Open an existing file-backed ring. Validates magic + capacity.

Source

pub fn create_from_shm(shm: ShmFile, capacity: usize) -> Result<Self, RingError>

Build a fresh ring on top of a named RAM-resident shared-memory backing. Cross-process visible via the logical_name of the underlying ShmFile; never touches the page cache. The ShmFile must be sized to at least spsc_ring_file_size(capacity) bytes.

Source

pub fn open_from_shm( shm: ShmFile, expected_capacity: usize, ) -> Result<Self, RingError>

Open an existing named ShmFs-backed ring. Validates magic + capacity. Does NOT re-initialize the layout - the layout must already be present from a prior create_from_shm on the same logical name.

Source

pub fn create_in_region<R: RegionOwner>( region: R, capacity: usize, ) -> Result<Self, RingError>

Build a fresh ring laid out in caller-owned memory (huge / large pages, or any RegionOwner). The region must be at least spsc_ring_file_size(capacity) bytes; the ring owns it for its lifetime so the pages stay mapped.

Source

pub fn open_in_region<R: RegionOwner>( region: R, expected_capacity: usize, ) -> Result<Self, RingError>

Attach to an existing ring already laid out in region - e.g. a LargePageSection another process created under the same name. Validates the header and does NOT re-initialise.

Source

pub fn capacity(&self) -> usize

Capacity in slots (always a power of 2).

Source

pub fn head(&self) -> u64

Producer’s published index. Cross-thread visible.

Source

pub fn tail(&self) -> u64

Consumer’s published index. Cross-thread visible.

Source

pub fn head_signal(&self) -> &AtomicU64

The producer’s publish signal: the head counter the consumer-side monitor-wait arms on. The producer’s Release-store to this atom on every push is the wake.

Source

pub fn approx_len(&self) -> usize

Number of items waiting (head - tail).

Source

pub fn try_push(&self, payload: &[u8]) -> Result<(), RingError>

SPSC push. Caller is the sole producer (enforced by the Producer newtype that owns this ring via Arc). Lamport pattern: read tail to check fullness, write payload, Release- store head to publish.

Source

pub fn try_pop(&self, out: &mut [u8]) -> Result<usize, RingError>

SPSC pop. Caller is the sole consumer. Lamport pattern: read head to check emptiness, read payload, Release-store tail to free the slot.

Source

pub fn peek_slot(&self) -> Option<PeekedSlot<'_>>

Peek the next slot WITHOUT copying or releasing it. Returns a PeekedSlot guard that derefs to &[u8] pointing directly into the mapped region. Caller passes this slice to downstream consumers (e.g. quinn’s SendStream::write_all) without an intermediate copy. When done, call PeekedSlot::confirm to advance the consumer position and release the slot. Drop without confirming leaves the slot in place; the next peek_slot returns it again.

Returns None when the ring is empty. Caller is the sole consumer.

Source

pub fn flush(&self) -> Result<(), RingError>

Force any dirty MMF pages to disk. Only meaningful for the file-backed mode; no-op on anonymous and ShmFs mappings (which never touch disk).

Trait Implementations§

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.