pub struct Fifo<const L: usize, const F: usize, T> { /* private fields */ }
Expand description
Shared First-In/First-Out Buffer
§Principle
The methods on this object work by negociating how many items can be pushed or pulled based on atomic integer operations.
When you push N items, a reservation of N slots will be made in the buffer. Once the reservation is made, the items are written into the slots and they are marked as “produced”.
When you try to pull some items from the buffer, first
a negociation takes place based on constraints specified
by the Storage
implementation you provide. If the number
of available items meets these constraints, these items are
extracted from the buffer.
§Fifo vs Channel
Realistically, someone would use channels instead of this. Channels provide distinct producer/consumer handles for one FIFO, which makes code easier to understand.
§Memory Footprint
- This structure has a size of 68 bytes.
- It has a boxed 24-byte block recycle bin.
- The recycle bin has a growable buffer of 16-byte elements.
- Each block as a size of
16 + F x (2 + 8 x sz(item))
bytes.
For basic uses, the overall memory footprint of this structure should be in the hundreds of bytes.
Trait Implementations§
Source§impl<const L: usize, const F: usize, T> FifoApi<T> for Fifo<L, F, T>
impl<const L: usize, const F: usize, T> FifoApi<T> for Fifo<L, F, T>
Source§fn push(&self, iter: &mut dyn ExactSizeIterator<Item = T>)
fn push(&self, iter: &mut dyn ExactSizeIterator<Item = T>)
Inserts all the items from an iterator into the FIFO, atomically
The order of the items is preserved, and they will be inserted consecutively; other pushes from other tasks will not interfere.
This method doesn’t spin, yield or sleeps; it should complete rather immediately. The only think that can take time here is an occasional memory allocation.
Source§fn pull(&self, storage: &mut dyn InternalStorageApi<T>) -> usize
fn pull(&self, storage: &mut dyn InternalStorageApi<T>) -> usize
Retrieves some elements from the FIFO, atomically
If the number of available items doesn’t meet the constraints
of the storage
parameter, this returns zero.
This method doesn’t spin, yield or sleeps; it should complete rather immediately. The only think that can take time here is an occasional memory allocation.