Skip to content
This repository was archived by the owner on Jan 4, 2026. It is now read-only.

Commit 5efea72

Browse files
committed
Add test, fmt
1 parent 322db63 commit 5efea72

5 files changed

Lines changed: 50 additions & 4 deletions

File tree

src/queue.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,3 +106,31 @@ impl<S: Storage, C: Coord, N: Notifier> crate::queue::ArcBBQueue<S, C, N> {
106106
}
107107
}
108108
}
109+
110+
#[cfg(test)]
111+
mod test {
112+
use crate::traits::{
113+
coordination::cas::AtomicCoord, notifier::blocking::Blocking, storage::Inline,
114+
};
115+
116+
use super::*;
117+
118+
type Queue = BBQueue<Inline<4096>, AtomicCoord, Blocking>;
119+
static QUEUE: Queue = BBQueue::new();
120+
static PRODUCER: FramedProducer<&'static Queue, u16> = QUEUE.framed_producer();
121+
static CONSUMER: FramedConsumer<&'static Queue, u16> = QUEUE.framed_consumer();
122+
123+
#[test]
124+
fn handles() {
125+
let mut wgr = PRODUCER.grant(16).unwrap();
126+
wgr.iter_mut().for_each(|w| *w = 123);
127+
wgr.commit(16);
128+
129+
let rgr = CONSUMER.read().unwrap();
130+
assert_eq!(rgr.len(), 16);
131+
for b in rgr.iter() {
132+
assert_eq!(*b, 123);
133+
}
134+
rgr.release();
135+
}
136+
}

src/traits/bbqhdl.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,13 @@
1717
1818
use core::{marker::PhantomData, ops::Deref};
1919

20-
use crate::{prod_cons::{framed::{FramedConsumer, FramedProducer, LenHeader}, stream::{StreamConsumer, StreamProducer}}, queue::BBQueue};
20+
use crate::{
21+
prod_cons::{
22+
framed::{FramedConsumer, FramedProducer, LenHeader},
23+
stream::{StreamConsumer, StreamProducer},
24+
},
25+
queue::BBQueue,
26+
};
2127

2228
use super::{coordination::Coord, notifier::Notifier, storage::Storage};
2329

src/traits/coordination/cas.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,11 @@ unsafe impl Coord for AtomicCoord {
6565
self.last.store(0, Ordering::Release);
6666
}
6767

68-
fn grant_max_remaining(&self, capacity: usize, mut sz: usize) -> Result<(usize, usize), WriteGrantError> {
68+
fn grant_max_remaining(
69+
&self,
70+
capacity: usize,
71+
mut sz: usize,
72+
) -> Result<(usize, usize), WriteGrantError> {
6973
if self.write_in_progress.swap(true, Ordering::AcqRel) {
7074
return Err(WriteGrantError::GrantInProgress);
7175
}

src/traits/coordination/cs.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,11 @@ unsafe impl Coord for CsCoord {
7171
self.last.store(0, Ordering::Release);
7272
}
7373

74-
fn grant_max_remaining(&self, capacity: usize, mut sz: usize) -> Result<(usize, usize), WriteGrantError> {
74+
fn grant_max_remaining(
75+
&self,
76+
capacity: usize,
77+
mut sz: usize,
78+
) -> Result<(usize, usize), WriteGrantError> {
7579
critical_section::with(|_cs| {
7680
if self.write_in_progress.load(Ordering::Relaxed) {
7781
return Err(WriteGrantError::GrantInProgress);

src/traits/coordination/mod.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,11 @@ pub unsafe trait Coord {
5454

5555
// Write Grants
5656

57-
fn grant_max_remaining(&self, capacity: usize, sz: usize) -> Result<(usize, usize), WriteGrantError>;
57+
fn grant_max_remaining(
58+
&self,
59+
capacity: usize,
60+
sz: usize,
61+
) -> Result<(usize, usize), WriteGrantError>;
5862
fn grant_exact(&self, capacity: usize, sz: usize) -> Result<usize, WriteGrantError>;
5963
fn commit_inner(&self, capacity: usize, grant_len: usize, used: usize);
6064

0 commit comments

Comments
 (0)