Skip to main content

BufPool

Struct BufPool 

Source
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

Source

pub fn new(cfg: BPCfg) -> Self

Create a new BufPool

§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(4).unwrap();
assert_eq!(alloc.count, 4);
Source

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§

Source§

impl Debug for BufPool

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Drop for BufPool

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl Send for BufPool

Source§

impl Sync for BufPool

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.