-
Notifications
You must be signed in to change notification settings - Fork 214
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move AtomicWaker, reimplement using Generic
- Loading branch information
Showing
3 changed files
with
33 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
//! Asynchronous utilities. | ||
use core::task::Waker; | ||
|
||
use embassy_sync::waitqueue::GenericAtomicWaker; | ||
|
||
use crate::sync::RawMutex; | ||
|
||
/// Utility struct to register and wake a waker. | ||
pub struct AtomicWaker { | ||
waker: GenericAtomicWaker<RawMutex>, | ||
} | ||
|
||
impl AtomicWaker { | ||
/// Create a new `AtomicWaker`. | ||
#[allow(clippy::new_without_default)] | ||
pub const fn new() -> Self { | ||
Self { | ||
waker: GenericAtomicWaker::new(RawMutex::new()), | ||
} | ||
} | ||
|
||
delegate::delegate! { | ||
to self.waker { | ||
/// Register a waker. Overwrites the previous waker, if any. | ||
pub fn register(&self, w: &Waker); | ||
/// Wake the registered waker, if any. | ||
pub fn wake(&self); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters