#[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: AtomicU32Current peer state (Empty / Attached / Goodbye / Reserved).
epoch: AtomicU32Incremented on each attach; used as an ABA counter for crash recovery.
last_heartbeat: AtomicU64Monotonic clock reading (nanoseconds) of the last heartbeat.
ring_offset: u64Byte offset from the start of the segment to this guest’s BipBuffer pair.
_reserved: [u8; 40]Implementations§
Source§impl PeerEntry
impl PeerEntry
Sourcepub unsafe fn init(&mut self, ring_offset: u64)
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.
Sourcepub fn try_attach(&self) -> Result<u32, PeerState>
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.
Sourcepub fn try_reserve(&self) -> Result<u32, PeerState>
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.
Sourcepub fn try_claim_reserved(&self) -> Result<(), PeerState>
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.
Sourcepub fn release_reserved(&self)
pub fn release_reserved(&self)
Release a reserved slot back to Empty (called by host if spawn fails).
Sourcepub fn set_goodbye(&self)
pub fn set_goodbye(&self)
Mark this slot as Goodbye (orderly detach or crash detected by host).
Sourcepub fn update_heartbeat(&self, timestamp_ns: u64)
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]
Sourcepub fn last_heartbeat(&self) -> u64
pub fn last_heartbeat(&self) -> u64
Read the last recorded heartbeat timestamp.
Sourcepub fn is_heartbeat_stale(&self, current_time_ns: u64, interval_ns: u64) -> bool
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).