Skip to main content

esp_hal/
asynch.rs

1//! Asynchronous utilities.
2use core::task::Waker;
3
4use embassy_sync::waitqueue::GenericAtomicWaker;
5use esp_sync::RawMutex;
6
7/// Utility struct to register and wake a waker.
8pub struct AtomicWaker {
9    waker: GenericAtomicWaker<RawMutex>,
10}
11
12impl AtomicWaker {
13    /// Create a new `AtomicWaker`.
14    #[allow(clippy::new_without_default)]
15    pub const fn new() -> Self {
16        Self {
17            waker: GenericAtomicWaker::new(RawMutex::new()),
18        }
19    }
20
21    /// Register a waker. Overwrites the previous waker, if any.
22    #[inline]
23    pub fn register(&self, w: &Waker) {
24        self.waker.register(w);
25    }
26
27    /// Wake the registered waker, if any.
28    #[crate::ram]
29    pub fn wake(&self) {
30        self.waker.wake();
31    }
32}