pub struct ConcurrentHandleAllocator<T> { /* private fields */ }Expand description
A thread-safe handle allocator using parking_lot primitives.
This allocator allows concurrent read access and synchronized write access. Use this when handles need to be shared across threads.
§Performance Characteristics
- Reads (
get): UsesRwLock, multiple concurrent readers allowed - Writes (
allocate,deallocate): Briefly locks a mutex for the free list
§Example
ⓘ
use std::sync::Arc;
let allocator = Arc::new(ConcurrentHandleAllocator::new());
// Clone for another thread
let alloc_clone = Arc::clone(&allocator);
std::thread::spawn(move || {
let handle = alloc_clone.allocate(42);
// ...
});Implementations§
Source§impl<T> ConcurrentHandleAllocator<T>
impl<T> ConcurrentHandleAllocator<T>
Sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Creates a concurrent allocator with pre-allocated capacity.
Sourcepub fn allocate(&self, value: T) -> Handle<T>
pub fn allocate(&self, value: T) -> Handle<T>
Allocates a handle for the given value.
This operation briefly locks the free list and entries for writing.
Sourcepub fn deallocate(&self, handle: Handle<T>) -> Option<T>
pub fn deallocate(&self, handle: Handle<T>) -> Option<T>
Deallocates a handle, returning the value if the handle was valid.
Trait Implementations§
Source§impl<T: Debug> Debug for ConcurrentHandleAllocator<T>
impl<T: Debug> Debug for ConcurrentHandleAllocator<T>
Auto Trait Implementations§
impl<T> !Freeze for ConcurrentHandleAllocator<T>
impl<T> !RefUnwindSafe for ConcurrentHandleAllocator<T>
impl<T> Send for ConcurrentHandleAllocator<T>where
T: Send,
impl<T> Sync for ConcurrentHandleAllocator<T>
impl<T> Unpin for ConcurrentHandleAllocator<T>where
T: Unpin,
impl<T> UnwindSafe for ConcurrentHandleAllocator<T>where
T: UnwindSafe,
Blanket Implementations§
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more