pub struct Arena<K, V, const N: usize> { /* private fields */ }Expand description
A lock-free static memory pool for Nodes using tagged indices to prevent ABA.
Implementations§
Source§impl<K, V, const N: usize> Arena<K, V, N>
impl<K, V, const N: usize> Arena<K, V, N>
pub const fn new() -> Self
Sourcepub fn alloc(
&self,
key: K,
value: V,
node: *mut ThreadStateNode,
) -> Option<usize>
pub fn alloc( &self, key: K, value: V, node: *mut ThreadStateNode, ) -> Option<usize>
Allocates a node from the free list and initializes it. Returns the index of the allocated node.
§Safety
node must be a valid pointer.
Sourcepub unsafe fn free(&self, index: usize)
pub unsafe fn free(&self, index: usize)
Safely frees a node, running its drop logic, and returning it to the free list. MUST only be called when no threads are reading the node (e.g., via QSBR).
Sourcepub unsafe fn drop_node(&self, index: usize)
pub unsafe fn drop_node(&self, index: usize)
Drops the inner item without pushing it to the free list.
pub fn set_next_free(&self, index: u32, next: u32)
Sourcepub unsafe fn free_batch(&self, head_idx: u32, tail_idx: u32)
pub unsafe fn free_batch(&self, head_idx: u32, tail_idx: u32)
Pushes a batch of nodes to the global free list without dropping it.
Sourcepub unsafe fn free_raw(&self, index: usize)
pub unsafe fn free_raw(&self, index: usize)
Pushes a node index to the global free list without dropping it.
Sourcepub unsafe fn get(&self, index: usize) -> &Node<K, V>
pub unsafe fn get(&self, index: usize) -> &Node<K, V>
Get a reference to a node. Caller must ensure index is valid and the node is currently allocated.
pub unsafe fn get_mut(&self, index: usize) -> &mut Node<K, V>
Trait Implementations§
impl<K: Send, V: Send, const N: usize> Send for Arena<K, V, N>
impl<K: Sync, V: Sync, const N: usize> Sync for Arena<K, V, N>
Auto Trait Implementations§
impl<K, V, const N: usize> !Freeze for Arena<K, V, N>
impl<K, V, const N: usize> !RefUnwindSafe for Arena<K, V, N>
impl<K, V, const N: usize> Unpin for Arena<K, V, N>
impl<K, V, const N: usize> UnsafeUnpin for Arena<K, V, N>where
K: UnsafeUnpin,
V: UnsafeUnpin,
impl<K, V, const N: usize> UnwindSafe for Arena<K, V, N>where
K: UnwindSafe,
V: UnwindSafe,
Blanket Implementations§
Source§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
Source§type ArchivedMetadata = ()
type ArchivedMetadata = ()
The archived version of the pointer metadata for this type.
Source§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
Converts some archived metadata to the pointer metadata for itself.
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more