Skip to main content

ShmRing

Struct ShmRing 

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

Cross-process ring buffer backed by a POSIX SHM segment.

Use ShmRing::open_or_create to attach to (or create) the segment by name. Multiple processes calling this with the same name and matching RingSpec share the underlying memory; the first process to call it does the one-time header initialization.

Implementations§

Source§

impl ShmRing

Source

pub fn open_or_create( fleet_name: &str, kind: u8, spec: RingSpec, ) -> Result<Self>

Open or create a SHM-backed ring under fleet_name for type kind kind with spec. The first process to call this initializes the header; later attachers reuse it.

Source

pub fn open_or_create_for_fleet( fleet_name: &str, kind: u8, spec: RingSpec, fleet_capacity: u16, ) -> Result<Self>

Open or create a SHM-backed ring using fleet_capacity physical writer lanes when spec is RingTopology::PerNode.

Source

pub fn created(&self) -> bool

True when this handle was the one that created the SHM segment (vs attaching to an already-existing one).

Remove the SHM segment name. Existing mappings stay valid; new opens will fail until open_or_create recreates it. Call from the owner process at fleet shutdown.

Source

pub fn kind(&self) -> u8

The KIND byte this ring carries.

Source

pub fn capacity(&self) -> usize

Slot count per lane.

Source

pub fn lane_count(&self) -> usize

Number of physical writer lanes in this segment.

Source

pub fn payload_capacity(&self) -> usize

Maximum inline payload bytes for this ring lane.

Source

pub fn spec(&self) -> RingSpec

Source

pub fn head(&self) -> u64

Head of the sole shared lane, or lane zero for a per-node ring.

Source

pub fn lane_head(&self, node_id: NodeId) -> u64

Current committed head for node_id’s lane.

Source

pub fn next_version(&self) -> u64

Allocate one non-zero semantic version shared by all writer lanes and processes attached to this ring.

Source

pub fn current_version(&self) -> u64

Last semantic version allocated by any process attached to this ring.

Source

pub fn write( &self, node_id: NodeId, frame_kind: u8, ver: u64, payload: Bytes, ) -> Result<NetId64>

Append a frame. Atomically reserves the next counter, mints the NetId64, writes the slot. Returns the minted id.

Source

pub fn write_batch( &self, node_id: NodeId, frame_kind: u8, ver: u64, payloads: Vec<Bytes>, ) -> Result<Vec<NetId64>>

Append one contiguous batch to a lane and return consecutive ids.

Per-node and shared-ordered lane heads advance only after the complete batch has committed. The batch may not exceed the ring capacity.

Source

pub fn read(&self, id: NetId64) -> Option<Frame>

Read the slot whose counter matches id.counter(). Returns None if the slot has been overwritten, was never written, or a torn read could not be reconciled across two retries.

Source

pub fn read_head(&self) -> Option<Frame>

Read the most recent frame (head - 1). Returns None if no write has happened yet, or a torn read could not resolve.

Source

pub fn read_at(&self, counter: u64) -> Option<Frame>

Read whatever frame currently occupies the slot at counter % capacity, regardless of which counter is stored there. Used by walking readers that need slot-by-slot access without knowing the writer’s NetId64 ahead of time.

Source

pub fn read_lane_at(&self, node_id: NodeId, counter: u64) -> Option<Frame>

Read the frame currently occupying node_id’s lane slot.

Source

pub fn reset(&self)

Clear all slots and reset every lane head to zero.

Intended for owner-controlled boot-time cleanup. Do not call while other processes are publishing to this ring: it rewrites the shared slot memory in place.

Trait Implementations§

Source§

impl RingFrameSource for ShmRing

Available on Unix only.
Source§

fn kind(&self) -> u8

The OrbitTyped::KIND carried by this ring.
Source§

fn head(&self) -> u64

Monotonic visible head. Depending on topology, this counts counters reserved by writers or frames committed by writers.
Source§

fn capacity(&self) -> usize

Fixed slot count for this ring.
Source§

fn read_at(&self, counter: u64) -> Option<Frame>

Read the frame currently occupying counter % capacity.
Source§

fn read_state_at(&self, counter: u64) -> RingRead

Classify the logical counter currently addressed by counter % capacity. Read more

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.