Skip to content

Commit 4c13fee

Browse files
authored
bbq2 is the new bbqueue (jamesmunns#119)
* A few docs and organization changes * bbq2 is the new bbqueue * bless bbq2 as bbqueue * Update some remaining bbq2s * Fix docs Closes jamesmunns#112
1 parent dfdaa8b commit 4c13fee

File tree

26 files changed

+91
-729
lines changed

26 files changed

+91
-729
lines changed

.github/workflows/build.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ on:
99

1010
defaults:
1111
run:
12-
working-directory: ./bbq2
12+
working-directory: ./bbqueue
1313

1414
jobs:
1515
build:
@@ -23,22 +23,22 @@ jobs:
2323
# BUILD + TEST
2424
#
2525
# no features, on std
26-
- name: Check bbq2 (no features, on host)
26+
- name: Check bbqueue (no features, on host)
2727
run: cargo build --no-default-features
2828
# default features, on std
29-
- name: Check bbq2 (default features, on host)
29+
- name: Check bbqueue (default features, on host)
3030
run: cargo build
3131
# std features, on std
32-
- name: Check bbq2 (std features, on host)
32+
- name: Check bbqueue (std features, on host)
3333
run: cargo build --features=std
3434
# std features, on std, test
35-
- name: Test bbq2 (std features, on host)
35+
- name: Test bbqueue (std features, on host)
3636
run: cargo test --features=std
3737

3838
# no features, on mcu
39-
- name: Check bbq2 (no features, on mcu)
39+
- name: Check bbqueue (no features, on mcu)
4040
run: cargo build --no-default-features --target=thumbv6m-none-eabi
4141
# default features, on mcu
42-
- name: Check bbq2 (no features, on mcu)
42+
- name: Check bbqueue (no features, on mcu)
4343
run: cargo build --target=thumbv6m-none-eabi
4444

.github/workflows/miri.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ on:
99

1010
defaults:
1111
run:
12-
working-directory: ./bbq2
12+
working-directory: ./bbqueue
1313

1414
jobs:
1515
miri:
@@ -22,5 +22,5 @@ jobs:
2222
#
2323
# crate
2424
#
25-
- name: Miri test bbq2
25+
- name: Miri test bbqueue
2626
run: ./miri.sh

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[workspace]
22
resolver = "3"
33
members = [
4-
"bbq2",
4+
"bbqueue",
55
"legacy-bbqtest",
66
"legacy-core",
77
]

README.md

Lines changed: 47 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@
22

33
[![Documentation](https://docs.rs/bbqueue/badge.svg)](https://docs.rs/bbqueue)
44

5+
# BBQueue
6+
57
BBQueue, short for "BipBuffer Queue", is a Single Producer Single Consumer,
68
lockless, no_std, thread safe, queue, based on [BipBuffers]. For more info on
79
the 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
3034
let 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

5776
fn 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

Comments
 (0)