|
1 | 1 | use core::marker::PhantomData; |
2 | 2 |
|
3 | | -use crate::{prod_cons::{framed::{FramedConsumer, FramedProducer}, stream::{StreamConsumer, StreamProducer}}, traits::{ |
4 | | - bbqhdl::BbqHandle, coordination::Coord, notifier::Notifier, storage::{ConstStorage, Storage} |
5 | | -}}; |
| 3 | +use crate::{ |
| 4 | + prod_cons::{ |
| 5 | + framed::{FramedConsumer, FramedProducer}, |
| 6 | + stream::{StreamConsumer, StreamProducer}, |
| 7 | + }, |
| 8 | + traits::{ |
| 9 | + coordination::Coord, |
| 10 | + notifier::Notifier, |
| 11 | + storage::{ConstStorage, Storage}, |
| 12 | + }, |
| 13 | +}; |
| 14 | + |
| 15 | +#[cfg(feature = "std")] |
| 16 | +use crate::traits::bbqhdl::BbqHandle; |
6 | 17 |
|
7 | 18 | /// A standard bbqueue |
8 | 19 | pub struct BBQueue<S, C, N> { |
@@ -43,32 +54,27 @@ impl<S: ConstStorage, C: Coord, N: Notifier> BBQueue<S, C, N> { |
43 | 54 | } |
44 | 55 | } |
45 | 56 |
|
46 | | - |
47 | 57 | impl<S: Storage, C: Coord, N: Notifier> BBQueue<S, C, N> { |
48 | | - pub fn framed_producer(&self) -> FramedProducer<&'_ Self> { |
| 58 | + pub const fn framed_producer(&self) -> FramedProducer<&'_ Self> { |
49 | 59 | FramedProducer { |
50 | | - bbq: self.bbq_ref(), |
| 60 | + bbq: self, |
51 | 61 | pd: PhantomData, |
52 | 62 | } |
53 | 63 | } |
54 | 64 |
|
55 | | - pub fn framed_consumer(&self) -> FramedConsumer<&'_ Self> { |
| 65 | + pub const fn framed_consumer(&self) -> FramedConsumer<&'_ Self> { |
56 | 66 | FramedConsumer { |
57 | | - bbq: self.bbq_ref(), |
| 67 | + bbq: self, |
58 | 68 | pd: PhantomData, |
59 | 69 | } |
60 | 70 | } |
61 | 71 |
|
62 | | - pub fn stream_producer(&self) -> StreamProducer<&'_ Self> { |
63 | | - StreamProducer { |
64 | | - bbq: self.bbq_ref(), |
65 | | - } |
| 72 | + pub const fn stream_producer(&self) -> StreamProducer<&'_ Self> { |
| 73 | + StreamProducer { bbq: self } |
66 | 74 | } |
67 | 75 |
|
68 | | - pub fn stream_consumer(&self) -> StreamConsumer<&'_ Self> { |
69 | | - StreamConsumer { |
70 | | - bbq: self.bbq_ref(), |
71 | | - } |
| 76 | + pub const fn stream_consumer(&self) -> StreamConsumer<&'_ Self> { |
| 77 | + StreamConsumer { bbq: self } |
72 | 78 | } |
73 | 79 | } |
74 | 80 |
|
@@ -100,3 +106,31 @@ impl<S: Storage, C: Coord, N: Notifier> crate::queue::ArcBBQueue<S, C, N> { |
100 | 106 | } |
101 | 107 | } |
102 | 108 | } |
| 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 | +} |
0 commit comments