Skip to main content

VarSlotPool

Struct VarSlotPool 

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

Lock-free slot allocator operating on a shared memory Region.

r[impl shm.varslot]

Implementations§

Source§

impl VarSlotPool

Source

pub fn layout(configs: &[SizeClassConfig]) -> PoolLayout

Compute the byte offsets of each class’s metadata and data arrays, plus the total size required.

Both init and attach use this to reconstruct the layout from the same configs slice.

Source

pub fn required_size(configs: &[SizeClassConfig]) -> usize

Total bytes this pool needs in the region.

Source

pub unsafe fn discover_configs( region: Region, base_offset: usize, num_classes: u32, ) -> Result<Vec<SizeClassConfig>, &'static str>

Discover size-class configs from the in-segment class headers.

§Safety

region must point to a valid mapped segment region and base_offset must be the var-slot pool base from the segment header.

Source

pub unsafe fn init( region: Region, base_offset: usize, configs: &[SizeClassConfig], ) -> Self

Initialize a new pool in region at base_offset.

Writes all headers and builds the initial free lists. The region bytes must already be zeroed (segment creation zeros the mmap).

§Safety

region must be exclusively owned (no concurrent readers/writers). base_offset must be 64-byte aligned.

r[impl shm.varslot.slot-meta]

Source

pub unsafe fn attach( region: Region, base_offset: usize, configs: &[SizeClassConfig], ) -> Self

Attach to an existing, already-initialized pool.

§Safety

The pool at base_offset must have been initialized with the same configs.

Source

pub fn allocate(&self, size: u32, owner_peer: u8) -> Option<SlotRef>

Allocate a slot for a payload of size bytes.

Finds the smallest size class where slot_size >= size and pops from its free list. If that class is exhausted, tries the next larger one. Returns None if all suitable classes are exhausted (backpressure).

r[impl shm.varslot.selection] r[impl shm.varslot.allocate]

Source

pub fn free(&self, slot_ref: SlotRef) -> Result<(), DoubleFreeError>

Free a previously allocated slot.

Verifies the generation matches to detect double-frees, then pushes the slot back onto the class’s Treiber free list.

r[impl shm.varslot.free]

Source

pub unsafe fn slot_data_mut<'a>(&self, slot_ref: &SlotRef) -> &'a mut [u8]

Return a mutable slice into the slot’s data area.

§Safety

The slot must be currently allocated and the caller must ensure no concurrent access to the same slot’s data.

Source

pub unsafe fn slot_data<'a>(&self, slot_ref: &SlotRef) -> &'a [u8]

Return an immutable slice into the slot’s data area.

§Safety

The slot must be currently allocated and contain readable payload bytes.

Source

pub fn class_count(&self) -> usize

Return the number of size classes.

Source

pub fn slot_size(&self, class_idx: usize) -> u32

Return the slot size for a given class.

Source

pub fn reclaim_peer_slots(&self, peer_id: u8)

Crash recovery: reclaim all slots owned by peer_id back to their respective free lists.

Must be called only by the host after confirming the peer is dead.

r[impl shm.varslot.crash-recovery]

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.