pub struct BufferPool<const SLOTS: usize, const LEN: usize> { /* private fields */ }Expand description
Fixed-capacity pool of LEN-byte buffers. Declare as a static and call
Self::claim to obtain a BufferLease.
§Const-constructible
BufferPool::new() is const fn, so pools can be declared as static
items initialized at link time with no runtime cost.
§Minimum slot length
LEN must be at least 16 bytes — the size of a SOME/IP header — or the
client silently drops all inbound and rejects all sends. A compile-time
const assertion in Self::new enforces this floor. 16 is only the
absolute header minimum: in practice a slot must hold the largest expected
message (header + payload), realistically one full UDP datagram (see
crate::UDP_BUFFER_SIZE).
§Synchronization
Each slot has an independent AtomicBool claimed flag. claim() scans
for the first free slot and atomically claims it via
compare_exchange(false, true, AcqRel, Acquire). Drop releases via
store(false, Release). No global lock is taken; claim and release are
individually linearizable.
Implementations§
Source§impl<const SLOTS: usize, const LEN: usize> BufferPool<SLOTS, LEN>
impl<const SLOTS: usize, const LEN: usize> BufferPool<SLOTS, LEN>
Sourcepub const fn new() -> Self
pub const fn new() -> Self
Create a new, empty pool. All slots are free.
§Panics (compile-time)
A const assertion rejects LEN < 16 at compile time: a slot must be
large enough to hold a 16-byte SOME/IP header, otherwise the client
silently drops all inbound and rejects all sends.
Sourcepub fn claim(&'static self) -> Option<BufferLease>
pub fn claim(&'static self) -> Option<BufferLease>
Claim a free slot, returning a BufferLease, or None if all
SLOTS are in use.
The returned buffer is zeroed before hand-out so a reused slot never leaks the previous tenant’s bytes.
Source§impl<const SLOTS: usize, const LEN: usize> BufferPool<SLOTS, LEN>
impl<const SLOTS: usize, const LEN: usize> BufferPool<SLOTS, LEN>
Sourcepub fn claim_arc(self: &Arc<Self>) -> Option<BufferLease>
pub fn claim_arc(self: &Arc<Self>) -> Option<BufferLease>
Claim a free slot from an Arc-backed pool, returning a BufferLease
that holds an Arc clone to keep the pool alive for the lease’s
lifetime, or None if all SLOTS are in use.
This is the heap-backed counterpart to Self::claim: the static-pool
path uses &'static self and stores _owner: None; this path stores
_owner: Some(arc.clone()) so the pool’s backing store (and the slot’s
claimed flag) stay valid until the last lease and provider drop. Only
compiled where alloc is available (the _alloc feature), so the
bare-metal client,bare_metal build stays allocation-free.