Skip to main content

PeerEntry

Struct PeerEntry 

Source
#[repr(C)]
pub struct PeerEntry { pub state: AtomicU32, pub epoch: AtomicU32, pub last_heartbeat: AtomicU64, pub ring_offset: u64, pub _reserved: [u8; 40], }
Expand description

One 64-byte entry in the peer table.

r[impl shm.peer-table]

Fields§

§state: AtomicU32

Current peer state (Empty / Attached / Goodbye / Reserved).

§epoch: AtomicU32

Incremented on each attach; used as an ABA counter for crash recovery.

§last_heartbeat: AtomicU64

Monotonic clock reading (nanoseconds) of the last heartbeat.

§ring_offset: u64

Byte offset from the start of the segment to this guest’s BipBuffer pair.

§_reserved: [u8; 40]

Implementations§

Source§

impl PeerEntry

Source

pub unsafe fn init(&mut self, ring_offset: u64)

Write initial values for a new peer entry.

§Safety

self must point into exclusively-owned, zeroed memory.

Source

pub fn state(&self) -> PeerState

Read the current peer state.

Source

pub fn epoch(&self) -> u32

Read the current epoch.

Source

pub fn try_attach(&self) -> Result<u32, PeerState>

Attempt to attach: CAS Empty → Attached, increment epoch.

Returns Ok(new_epoch) on success, Err(actual) if the slot is not Empty.

Source

pub fn try_reserve(&self) -> Result<u32, PeerState>

Reserve this slot before spawning a guest: CAS Empty → Reserved, increment epoch.

Returns Ok(new_epoch) on success, Err(actual) if the slot is not Empty.

Source

pub fn try_claim_reserved(&self) -> Result<(), PeerState>

Claim a reserved slot: CAS Reserved → Attached.

Called by a spawned guest to complete the attach handshake. Returns Ok(()) on success, Err(actual) if the slot is not Reserved.

Source

pub fn release_reserved(&self)

Release a reserved slot back to Empty (called by host if spawn fails).

Source

pub fn set_goodbye(&self)

Mark this slot as Goodbye (orderly detach or crash detected by host).

Source

pub fn reset(&self)

Reset to Empty (crash recovery — called by host after reclaiming slots).

Source

pub fn update_heartbeat(&self, timestamp_ns: u64)

Write the current heartbeat timestamp.

timestamp_ns must be a monotonic clock reading in nanoseconds.

r[impl shm.crash.heartbeat-clock]

Source

pub fn last_heartbeat(&self) -> u64

Read the last recorded heartbeat timestamp.

Source

pub fn is_heartbeat_stale(&self, current_time_ns: u64, interval_ns: u64) -> bool

Return true if the heartbeat is stale (peer likely crashed).

A heartbeat is stale when current_time_ns - last_heartbeat > 2 * interval_ns. Always returns false when interval_ns == 0 (heartbeats disabled).

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.