-
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
currently, `maitake` has a `wait` module, which contains `WaitCell`, `WaitQueue`, `WaitMap`, and (as of #301) `Semaphore`. in addition, it has a separate `sync` module, which currently contains `Mutex` and nothing else (and may grow a `RwLock` eventually/soon). this feels a bit unfortunate --- the `wait` types are also synchronization primitives. this branch moves all of `maitake::wait` into `maitake::sync`. in addition,i fixed up the docs a little bit. closes #302
- Loading branch information
Showing
16 changed files
with
85 additions
and
74 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 |
---|---|---|
|
@@ -17,4 +17,3 @@ pub mod future; | |
pub mod scheduler; | ||
pub mod sync; | ||
pub mod task; | ||
pub mod wait; |
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 |
---|---|---|
@@ -1,14 +1,55 @@ | ||
//! Synchronization primitives | ||
//! Asynchronous synchronization primitives | ||
//! | ||
//! This module contains the following asynchronous synchronization primitives: | ||
//! This module contains the following synchronization primitives: | ||
//! | ||
//! - [`Mutex`]: a fairly queued, asynchronous mutual exclusion lock. | ||
//! - [`Mutex`]: a fairly queued, asynchronous [mutual exclusion lock], for | ||
//! protecting shared data | ||
//! - [`Semaphore`]: an asynchronous [counting semaphore], for limiting the | ||
//! number of tasks which may run concurrently | ||
//! - [`WaitCell`], a cell that stores a *single* waiting task's [`Waker`], so | ||
//! that the task can be woken by another task, | ||
//! - [`WaitQueue`], a queue of waiting tasks, which are woken in first-in, | ||
//! first-out order | ||
//! - [`WaitMap`], a set of waiting tasks associated with keys, in which a task | ||
//! can be woken by its key | ||
//! | ||
//! [mutual exclusion lock]:https://en.wikipedia.org/wiki/Mutual_exclusion | ||
//! [counting semaphore]: https://en.wikipedia.org/wiki/Semaphore_(programming) | ||
//! [`Waker`]: core::task::Waker | ||
pub mod mutex; | ||
pub mod semaphore; | ||
pub(crate) mod wait_cell; | ||
pub mod wait_map; | ||
pub mod wait_queue; | ||
|
||
#[cfg(feature = "alloc")] | ||
#[doc(inline)] | ||
pub use self::mutex::OwnedMutexGuard; | ||
#[doc(inline)] | ||
pub use self::mutex::{Mutex, MutexGuard}; | ||
#[doc(inline)] | ||
pub use self::semaphore::Semaphore; | ||
pub use self::wait_cell::WaitCell; | ||
#[doc(inline)] | ||
pub use self::wait_map::WaitMap; | ||
#[doc(inline)] | ||
pub use self::wait_queue::WaitQueue; | ||
|
||
use core::task::Poll; | ||
|
||
/// An error indicating that a [`WaitCell`], [`WaitQueue`], [`WaitMap`], or | ||
/// [`Semaphore`] was closed while attempting to register a waiter. | ||
#[derive(Copy, Clone, Debug, Eq, PartialEq)] | ||
pub struct Closed(()); | ||
|
||
pub type WaitResult<T> = Result<T, Closed>; | ||
|
||
pub(in crate::sync) const fn closed<T>() -> Poll<WaitResult<T>> { | ||
Poll::Ready(Err(Closed::new())) | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests; | ||
impl Closed { | ||
pub(in crate::sync) const fn new() -> Self { | ||
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
File renamed without changes.
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
File renamed without changes.
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 was deleted.
Oops, something went wrong.
File renamed without changes.
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
File renamed without changes.
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
File renamed without changes.
This file was deleted.
Oops, something went wrong.