pub struct BufferPool<M: RawMutex, T, const N: usize> { /* private fields */ }Expand description
Pool of N buffers of type T, synchronized with mutex M.
Free slots are tracked with a u32 bitmask, so N must be in 1..=32.
Implementations§
Source§impl<M: RawMutex, T, const N: usize> BufferPool<M, T, N>
impl<M: RawMutex, T, const N: usize> BufferPool<M, T, N>
Sourcepub const fn new(buffer: [T; N]) -> Self
pub const fn new(buffer: [T; N]) -> Self
Creates a pool with the given backing storage; all slots start available.
§Valid N
N must be in 1..=32. Otherwise BufferPool::new panics when run, or fails
const evaluation if used in a const item.
Sourcepub fn try_take(&'static self) -> Option<BufferGuard<M, T>>
pub fn try_take(&'static self) -> Option<BufferGuard<M, T>>
Tries to take one buffer without blocking. Returns None if the pool is empty.
Sourcepub fn take(&'static self) -> impl Future<Output = BufferGuard<M, T>>
pub fn take(&'static self) -> impl Future<Output = BufferGuard<M, T>>
Waits until a buffer is available, then returns a guard.
If the pool is empty, the current task’s waker is registered; when another task
drops a BufferGuard or MappedBufferGuard, waiters are woken.
Trait Implementations§
impl<M: RawMutex + Send, T: Send, const N: usize> Send for BufferPool<M, T, N>
impl<M: RawMutex + Sync, T: Send, const N: usize> Sync for BufferPool<M, T, N>
Auto Trait Implementations§
impl<M, T, const N: usize> !Freeze for BufferPool<M, T, N>
impl<M, T, const N: usize> !RefUnwindSafe for BufferPool<M, T, N>
impl<M, T, const N: usize> Unpin for BufferPool<M, T, N>
impl<M, T, const N: usize> UnsafeUnpin for BufferPool<M, T, N>where
M: UnsafeUnpin,
T: UnsafeUnpin,
impl<M, T, const N: usize> UnwindSafe for BufferPool<M, T, N>where
M: UnwindSafe,
T: 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