bbqueue/traits/notifier/
maitake.rs1use const_init::ConstInit;
4use maitake_sync::WaitCell;
5
6use super::{AsyncNotifier, Notifier};
7
8pub struct MaiNotSpsc {
13 not_empty: WaitCell,
14 not_full: WaitCell,
15}
16
17impl MaiNotSpsc {
18 pub const fn new() -> Self {
20 Self::INIT
21 }
22}
23
24impl Default for MaiNotSpsc {
25 fn default() -> Self {
26 Self::new()
27 }
28}
29
30impl ConstInit for MaiNotSpsc {
31 #[allow(clippy::declare_interior_mutable_const)]
32 const INIT: Self = Self {
33 not_empty: WaitCell::new(),
34 not_full: WaitCell::new(),
35 };
36}
37
38impl Notifier for MaiNotSpsc {
39 fn wake_one_consumer(&self) {
40 _ = self.not_empty.wake();
41 }
42
43 fn wake_one_producer(&self) {
44 _ = self.not_full.wake();
45 }
46}
47
48impl AsyncNotifier for MaiNotSpsc {
49 async fn wait_for_not_empty<T, F: FnMut() -> Option<T>>(&self, f: F) -> T {
50 self.not_empty.wait_for_value(f).await.unwrap()
51 }
52
53 async fn wait_for_not_full<T, F: FnMut() -> Option<T>>(&self, f: F) -> T {
54 self.not_full.wait_for_value(f).await.unwrap()
55 }
56}