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
impl VarSlotPool
Sourcepub fn layout(configs: &[SizeClassConfig]) -> PoolLayout
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.
Sourcepub fn required_size(configs: &[SizeClassConfig]) -> usize
pub fn required_size(configs: &[SizeClassConfig]) -> usize
Total bytes this pool needs in the region.
Sourcepub unsafe fn discover_configs(
region: Region,
base_offset: usize,
num_classes: u32,
) -> Result<Vec<SizeClassConfig>, &'static str>
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.
Sourcepub unsafe fn init(
region: Region,
base_offset: usize,
configs: &[SizeClassConfig],
) -> Self
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]
Sourcepub unsafe fn attach(
region: Region,
base_offset: usize,
configs: &[SizeClassConfig],
) -> Self
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.
Sourcepub fn allocate(&self, size: u32, owner_peer: u8) -> Option<SlotRef>
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]
Sourcepub fn free(&self, slot_ref: SlotRef) -> Result<(), DoubleFreeError>
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]
Sourcepub unsafe fn slot_data_mut<'a>(&self, slot_ref: &SlotRef) -> &'a mut [u8] ⓘ
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.
Sourcepub unsafe fn slot_data<'a>(&self, slot_ref: &SlotRef) -> &'a [u8] ⓘ
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.
Sourcepub fn class_count(&self) -> usize
pub fn class_count(&self) -> usize
Return the number of size classes.
Sourcepub fn reclaim_peer_slots(&self, peer_id: u8)
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]