Skip to main content

hazard3_sync/waitqueue/
critical_section_waker.rs

1use core::task::Waker;
2
3use super::GenericAtomicWaker;
4use crate::blocking_mutex::raw::CriticalSectionRawMutex;
5
6/// Utility struct to register and wake a waker.
7pub struct CriticalSectionWaker {
8    waker: GenericAtomicWaker<CriticalSectionRawMutex>,
9}
10
11impl CriticalSectionWaker {
12    /// Create a new `CriticalSectionWaker`.
13    pub const fn new() -> Self {
14        Self {
15            waker: GenericAtomicWaker::new(CriticalSectionRawMutex::new()),
16        }
17    }
18
19    /// Register a waker. Overwrites the previous waker, if any.
20    pub fn register(&self, w: &Waker) {
21        self.waker.register(w);
22    }
23
24    /// Wake the registered waker, if any.
25    pub fn wake(&self) {
26        self.waker.wake();
27    }
28}