pub struct BufPool { /* private fields */ }Expand description
Lock-free buffer pool used for staging IO buffers
§Features
- RAII Safe
- Graceful Shutdown
- Lock-free fast path
§Pooling for allocations
Bufs are allocated in batches using BufPool::allocate, it may allocate fewer than requested, in such cases
caller should wait using [BufPool::wait] which block till any bufs are available to use again
Implementations§
Source§impl BufPool
impl BufPool
Sourcepub fn allocate(&self, n: usize) -> FrozenRes<Allocation>
pub fn allocate(&self, n: usize) -> FrozenRes<Allocation>
Allocate n buffers
§Blocking
For BPBackend::Prealloc backend, if the pool does not currently contain enough chunks, call is blocked
until all required chunks are allocated
§Fallback to BPBackend::Dynamic
For BPBackend::Prealloc backend, f n exceeds the pool capacity, the allocation is performed using the
BPBackend::Dynamic
§RAII
The Allocation is RAII safe, as the allocated buffers are automatically reused (or free’ed from memory w/
respect to the backend used) as the caller drops reference to the Allocation
§Example
use frozen_core::bpool::{BufPool, BPCfg, BPBackend};
let pool = BufPool::new(BPCfg {
mid: 0,
chunk_size: 0x20,
backend: BPBackend::Prealloc { capacity: 0x10 },
});
let alloc = pool.allocate(2).unwrap();
assert_eq!(alloc.count, 2);
assert_eq!(alloc.slots().len(), 2);Trait Implementations§
impl Send for BufPool
impl Sync for BufPool
Auto Trait Implementations§
impl !Freeze for BufPool
impl RefUnwindSafe for BufPool
impl Unpin for BufPool
impl UnsafeUnpin for BufPool
impl UnwindSafe for BufPool
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