-
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This commit adds a `WaitCell` primitive to `mycelium-async`, which stores a single waiter and notifies it. Signed-off-by: Eliza Weisman <[email protected]>
- Loading branch information
Showing
10 changed files
with
448 additions
and
4 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,10 @@ | ||
use super::Task; | ||
use mycelium_util::{intrusive::list, sync::spin}; | ||
pub(crate) struct TaskList { | ||
inner: spin::Mutex<Inner>, | ||
} | ||
|
||
struct Inner { | ||
list: list::List<Task>, | ||
closed: bool, | ||
} |
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 @@ | ||
//! Waiter cells and queues to allow tasks to wait for notifications. | ||
//! | ||
//! This module implements two types of structure for waiting: a [`WaitCell`], | ||
//! which stores a *single* waiting task, and a wait *queue*, which | ||
//! stores a queue of waiting tasks. | ||
mod cell; | ||
pub use cell::WaitCell; | ||
|
||
use core::task::Poll; | ||
|
||
/// An error indicating that a [`WaitCell`] or queue was closed while attempting | ||
/// register a waiter. | ||
#[derive(Clone, Debug)] | ||
pub struct Closed(()); | ||
|
||
pub type WaitResult = Result<(), Closed>; | ||
|
||
pub(in crate::wait) const fn closed() -> Poll<WaitResult> { | ||
Poll::Ready(Err(Closed::new())) | ||
} | ||
|
||
pub(in crate::wait) const fn notified() -> Poll<WaitResult> { | ||
Poll::Ready(Ok(())) | ||
} | ||
|
||
impl Closed { | ||
pub(in crate::wait) const fn new() -> Self { | ||
Self(()) | ||
} | ||
} |
Oops, something went wrong.