Skip to content

Commit

Permalink
feat: add one-shot mutex
Browse files Browse the repository at this point in the history
Signed-off-by: Martin Kröning <[email protected]>
  • Loading branch information
mkroening committed Apr 4, 2024
1 parent 2359fca commit 0de1978
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 12 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ generic_once_cell = "0.1"
interrupts = "0.1"
interrupt-mutex = "0.1"
lock_api = "0.4"
one-shot-mutex = "0.1.1"
spinning_top = "0.3"

[dev-dependencies]
Expand Down
32 changes: 20 additions & 12 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,17 +70,20 @@
//!
//! This crate provides a lot of type definitions for ease of use:
//!
//! | [`RawMutex`] | Base | With [`RawInterruptMutex`] |
//! | ------------------ | -------------------- | ----------------------------- |
//! | `R` | [`Mutex`] | [`InterruptMutex`] |
//! | [`RawSpinMutex`] | | [`RawInterruptSpinMutex`] |
//! | | [`SpinMutex`] | [`InterruptSpinMutex`] |
//! | | [`SpinMutexGuard`] | [`InterruptSpinMutexGuard`] |
//! | | [`OnceCell`] | [`InterruptOnceCell`] |
//! | | [`Lazy`] | [`InterruptLazy`] |
//! | [`RawTicketMutex`] | | [`RawInterruptTicketMutex`] |
//! | | [`TicketMutex`] | [`InterruptTicketMutex`] |
//! | | [`TicketMutexGuard`] | [`InterruptTicketMutexGuard`] |
//! | [`RawMutex`] | Base | With [`RawInterruptMutex`] |
//! | ------------------- | --------------------- | ------------------------------ |
//! | `R` | [`Mutex`] | [`InterruptMutex`] |
//! | [`RawSpinMutex`] | | [`RawInterruptSpinMutex`] |
//! | | [`SpinMutex`] | [`InterruptSpinMutex`] |
//! | | [`SpinMutexGuard`] | [`InterruptSpinMutexGuard`] |
//! | | [`OnceCell`] | [`InterruptOnceCell`] |
//! | | [`Lazy`] | [`InterruptLazy`] |
//! | [`RawOneShotMutex`] | | [`RawInterruptOneShotMutex`] |
//! | | [`OneShotMutex`] | [`InterruptOneShotMutex`] |
//! | | [`OneShotMutexGuard`] | [`InterruptOneShotMutexGuard`] |
//! | [`RawTicketMutex`] | | [`RawInterruptTicketMutex`] |
//! | | [`TicketMutex`] | [`InterruptTicketMutex`] |
//! | | [`TicketMutexGuard`] | [`InterruptTicketMutexGuard`] |
//!
//! [`RawMutex`]: lock_api::RawMutex
//! [`Mutex`]: lock_api::Mutex
Expand Down Expand Up @@ -113,9 +116,14 @@ pub use interrupts::without as without_interrupts;
pub use mutex::spin::{RawSpinMutex, SpinMutex, SpinMutexGuard};
pub use mutex::ticket::{RawTicketMutex, TicketMutex, TicketMutexGuard};
pub use mutex::{
InterruptSpinMutex, InterruptSpinMutexGuard, InterruptTicketMutex, InterruptTicketMutexGuard,
InterruptOneShotMutex, InterruptOneShotMutexGuard, InterruptSpinMutex, InterruptSpinMutexGuard,
InterruptTicketMutex, InterruptTicketMutexGuard, RawInterruptOneShotMutex,
RawInterruptSpinMutex, RawInterruptTicketMutex,
};
pub use one_shot_mutex::{
OneShotMutex, OneShotMutexGuard, OneShotRwLock, OneShotRwLockReadGuard,
OneShotRwLockUpgradableReadGuard, OneShotRwLockWriteGuard, RawOneShotMutex, RawOneShotRwLock,
};
pub use rwlock::{
RawRwSpinLock, RwSpinLock, RwSpinLockReadGuard, RwSpinLockUpgradableReadGuard,
RwSpinLockWriteGuard,
Expand Down
10 changes: 10 additions & 0 deletions src/mutex/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,19 @@ pub(crate) mod spin {
pub(crate) mod ticket;

use interrupt_mutex::RawInterruptMutex;
use one_shot_mutex::RawOneShotMutex;
use spin::RawSpinMutex;
use ticket::RawTicketMutex;

/// An interrupt-safe [`RawOneShotMutex`].
pub type RawInterruptOneShotMutex = RawInterruptMutex<RawOneShotMutex>;

/// A [`lock_api::Mutex`] based on [`RawInterruptOneShotMutex`].
pub type InterruptOneShotMutex<T> = lock_api::Mutex<RawInterruptOneShotMutex, T>;

/// A [`lock_api::MutexGuard`] based on [`RawInterruptOneShotMutex`].
pub type InterruptOneShotMutexGuard<'a, T> = lock_api::MutexGuard<'a, RawInterruptOneShotMutex, T>;

/// An interrupt-safe [`RawSpinMutex`].
pub type RawInterruptSpinMutex = RawInterruptMutex<RawSpinMutex>;

Expand Down

0 comments on commit 0de1978

Please sign in to comment.