pub struct TreiberSlab { /* private fields */ }Expand description
A lock-free slab allocator backed by a region.
This is a convenience wrapper around TreiberSlabRaw that manages
memory through a Region. All operations delegate to the raw implementation.
Implementations§
Source§impl TreiberSlab
impl TreiberSlab
Sourcepub unsafe fn init(
region: Region,
header_offset: usize,
slot_count: u32,
slot_size: u32,
) -> Self
pub unsafe fn init( region: Region, header_offset: usize, slot_count: u32, slot_size: u32, ) -> Self
Initialize a new slab at header_offset in the region.
§Safety
The region must be writable and exclusively owned during initialization.
Sourcepub unsafe fn attach(
region: Region,
header_offset: usize,
) -> Result<Self, &'static str>
pub unsafe fn attach( region: Region, header_offset: usize, ) -> Result<Self, &'static str>
Attach to an existing slab.
§Safety
The region must contain a valid, initialized slab header at header_offset.
Sourcepub fn inner(&self) -> &TreiberSlabRaw
pub fn inner(&self) -> &TreiberSlabRaw
Get a reference to the inner raw slab.
Sourcepub fn try_alloc(&self) -> AllocResult
pub fn try_alloc(&self) -> AllocResult
Try to allocate a slot.
Delegates to TreiberSlabRaw::try_alloc.
Sourcepub fn mark_in_flight(&self, handle: SlotHandle) -> Result<(), SlotError>
pub fn mark_in_flight(&self, handle: SlotHandle) -> Result<(), SlotError>
Mark a slot as in-flight (after enqueue).
Delegates to TreiberSlabRaw::mark_in_flight.
Sourcepub fn free(&self, handle: SlotHandle) -> Result<(), SlotError>
pub fn free(&self, handle: SlotHandle) -> Result<(), SlotError>
Free an in-flight slot and push it to the free list.
Delegates to TreiberSlabRaw::free.
Sourcepub fn free_allocated(&self, handle: SlotHandle) -> Result<(), SlotError>
pub fn free_allocated(&self, handle: SlotHandle) -> Result<(), SlotError>
Free a slot that is still Allocated (never sent).
Delegates to TreiberSlabRaw::free_allocated.
Sourcepub unsafe fn slot_data_ptr(&self, handle: SlotHandle) -> *mut u8
pub unsafe fn slot_data_ptr(&self, handle: SlotHandle) -> *mut u8
Sourcepub fn slot_count(&self) -> u32
pub fn slot_count(&self) -> u32
Returns the total number of slots.
Sourcepub fn free_count_approx(&self) -> u32
pub fn free_count_approx(&self) -> u32
Approximate number of free slots.