22
33[ ![ Documentation] ( https://docs.rs/bbqueue/badge.svg )] ( https://docs.rs/bbqueue )
44
5+ # BBQueue
6+
57BBQueue, short for "BipBuffer Queue", is a Single Producer Single Consumer,
68lockless, no_std, thread safe, queue, based on [ BipBuffers] . For more info on
79the design of the lock-free algorithm used by bbqueue, see [ this blog post] .
810
9- For a 90 minute guided tour of BBQueue, you can also view this [ guide on YouTube] .
10-
11- [ guide on YouTube ] : https://www.youtube.com/watch?v=ngTCf2cnGkY
1211[ BipBuffers ] : https://www.codeproject.com/articles/The-Bip-Buffer-The-Circular-Buffer-with-a-Twist
1312[ this blog post ] : https://ferrous-systems.com/blog/lock-free-ring-buffer/
1413
@@ -22,9 +21,14 @@ block of contiguous memory, which can be filled (or emptied) by a DMA engine.
2221## Local usage
2322
2423``` rust
24+ // The "Churrasco" flavor has inline storage, hardware atomic
25+ // support, no async support, and is not reference counted.
26+ use bbqueue :: nicknames :: Churrasco ;
27+
2528// Create a buffer with six elements
26- let bb : BBBuffer <6 > = BBBuffer :: new ();
27- let (mut prod , mut cons ) = bb . try_split (). unwrap ();
29+ let bb : Churrasco <6 > = Churrasco :: new ();
30+ let prod = bb . stream_producer ();
31+ let cons = bb . stream_consumer ();
2832
2933// Request space for one byte
3034let mut wgr = prod . grant_exact (1 ). unwrap ();
@@ -48,17 +52,32 @@ rgr.release(1);
4852
4953## Static usage
5054
51- ``` rust, no_run
52- use bbqueue::BBBuffer;
55+ ``` rust
56+ use bbqueue :: nicknames :: Churrasco ;
57+ use std :: {thread :: {sleep, spawn}, time :: Duration };
5358
5459// Create a buffer with six elements
55- static BB: BBBuffer<6> = BBBuffer::new();
60+ static BB : Churrasco <6 > = Churrasco :: new ();
61+
62+ fn receiver () {
63+ let cons = BB . stream_consumer ();
64+ loop {
65+ if let Ok (rgr ) = cons . read () {
66+ assert_eq! (rgr . len (), 1 );
67+ assert_eq! (rgr [0 ], 123 );
68+ rgr . release (1 );
69+ break ;
70+ }
71+ // don't do this in real code, use Notify!
72+ sleep (Duration :: from_millis (10 ));
73+ }
74+ }
5675
5776fn main () {
58- // Split the bbqueue into producer and consumer halves.
59- // These halves can be sent to different threads or to
60- // an interrupt handler for thread safe SPSC usage
61- let (mut prod, mut cons) = BB.try_split().unwrap( );
77+ let prod = BB . stream_producer ();
78+
79+ // spawn the consumer
80+ let hdl = spawn ( receiver );
6281
6382 // Request space for one byte
6483 let mut wgr = prod . grant_exact (1 ). unwrap ();
@@ -71,26 +90,28 @@ fn main() {
7190 // Make the data ready for consuming
7291 wgr . commit (1 );
7392
74- // Read all available bytes
75- let rgr = cons.read().unwrap();
93+ // make sure the receiver terminated
94+ hdl . join (). unwrap ();
95+ }
96+ ```
7697
77- assert_eq!(rgr[0], 123);
98+ ## Nicknames
7899
79- // Release the space for later writes
80- rgr.release(1);
100+ bbqueue uses generics to customize the data structure in four main ways:
81101
82- // The buffer cannot be split twice
83- assert!(BB.try_split().is_err());
84- }
85- ```
102+ * Whether the byte storage is inline (and const-generic), or heap allocated
103+ * Whether the queue is polling-only, or supports async/await sending/receiving
104+ * Whether the queue uses a lock-free algorithm with CAS atomics, or uses a critical section
105+ (for targets that don't have CAS atomics)
106+ * Whether the queue is reference counted, allowing Producer and Consumer halves to be passed
107+ around without lifetimes.
86108
87- The ` bbqueue ` crate is located in ` core/ ` , and tests are located in ` bbqtest/ ` .
109+ See the [ ` nicknames ` ] ( crate::nicknames ) module for all sixteen variants .
88110
89- ## Features
111+ ## Stability
90112
91- By default BBQueue uses atomic operations which are available on most platforms. However on some
92- (mostly embedded) platforms atomic support is limited and with the default features you will get
93- a compiler error about missing atomic methods.
113+ ` bbqueue ` v0.6 is a breaking change from the older "classic" v0.5 interfaces. The intent is to
114+ have a few minor breaking changes in early 2026, and to get to v1.0 as quickly as possible.
94115
95116
96117# License
0 commit comments