From 155145155b775176cdf6a6e3dce48fc059fe82ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kr=C3=B6ning?= Date: Wed, 3 Apr 2024 15:06:37 +0200 Subject: [PATCH] feat: add one-shot mutex MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Martin Kröning --- Cargo.toml | 1 + src/lib.rs | 29 +++++++++++++++++------------ src/mutex/mod.rs | 10 ++++++++++ 3 files changed, 28 insertions(+), 12 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 5d10f87..96df90f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" spinning_top = "0.3" [dev-dependencies] diff --git a/src/lib.rs b/src/lib.rs index c19b155..b6ffa08 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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 @@ -113,9 +116,11 @@ 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, RawOneShotMutex}; pub use rwlock::{ RawRwSpinLock, RwSpinLock, RwSpinLockReadGuard, RwSpinLockUpgradableReadGuard, RwSpinLockWriteGuard, diff --git a/src/mutex/mod.rs b/src/mutex/mod.rs index b148ae7..9d3bcce 100644 --- a/src/mutex/mod.rs +++ b/src/mutex/mod.rs @@ -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; + +/// A [`lock_api::Mutex`] based on [`RawInterruptOneShotMutex`]. +pub type InterruptOneShotMutex = lock_api::Mutex; + +/// 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;