BBQueue (BipBuffer Queue) is a Single Producer Single Consumer (SPSC), lockless, no_std, thread-safe queue based on the BipBuffer design.
Unlike standard circular/ring buffers where data must be pushed one piece at a time, BBQueue grants the user a block of contiguous memory. This makes it ideal for use with DMA (Direct Memory Access) on embedded systems, as a DMA engine can fill or empty a contiguous buffer without CPU intervention.
BBQueue uses generics to allow developers to customize four main aspects of the data structure:
- Storage: Inline (const-generic) or heap-allocated.
- Notification: Polling-only or async/await support.
- Coordination: Lock-free algorithm with CAS (Compare-And-Swap) atomics, or critical sections (for targets without CAS).
- Ownership: Reference counted (allowing Producer and Consumer halves to be passed around without lifetime constraints) or not.
use bbqueue::nicknames::Churrasco;
// Create a buffer with six elements
let bb: Churrasco<6> = Churrasco::new();
let prod = bb.stream_producer();
let cons = bb.stream_consumer();
// Request space for one byte
let mut wgr = prod.grant_exact(1).unwrap();
// Set the data
wgr[0] = 123;
assert_eq!(wgr.len(), 1);
// Make the data ready for consuming
wgr.commit(1);
// Read all available bytes
let rgr = cons.read().unwrap();
assert_eq!(rgr[0], 123);
// Release the space for later writes
rgr.release(1);