pub struct ShardedResourcePool<T> { /* private fields */ }Expand description
A sharded, binned resource pool designed for high-concurrency reuse of transient allocations.
Resources are partitioned by thread affinity across 4 shards to minimize lock contention, and internally binned into 64 power-of-two size classes. Pop operations use a non-blocking stealing fallback across shards.
Implementations§
Source§impl<T: SizeBounded> ShardedResourcePool<T>
impl<T: SizeBounded> ShardedResourcePool<T>
Sourcepub fn new(max_buffers: usize, max_bytes: u64) -> Self
pub fn new(max_buffers: usize, max_bytes: u64) -> Self
Construct a new pool with the given capacity limits.
Sourcepub fn take_at_least(&self, size: u64) -> Option<T>
pub fn take_at_least(&self, size: u64) -> Option<T>
Retrieve a resource of size >= size from the pool, or return None.
Sourcepub fn clear(&self)
pub fn clear(&self)
Clear all pooled resources.
All bin guards remain held until the bins are drained and the counters
are reset. This makes the reset a linearization point: a concurrent
recycle or take_at_least either completes before the reset or starts
after it, and cannot publish a resource behind zero counters.
Trait Implementations§
Auto Trait Implementations§
impl<T> !Freeze for ShardedResourcePool<T>
impl<T> !RefUnwindSafe for ShardedResourcePool<T>
impl<T> Send for ShardedResourcePool<T>
impl<T> Sync for ShardedResourcePool<T>
impl<T> Unpin for ShardedResourcePool<T>
impl<T> UnsafeUnpin for ShardedResourcePool<T>where
[Shard<T>; 4]: UnsafeUnpin,
impl<T> UnwindSafe for ShardedResourcePool<T>where
[Shard<T>; 4]: UnwindSafe,
Blanket Implementations§
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