diff --git a/Cargo.toml b/Cargo.toml index 1405416..6f70333 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,3 +20,6 @@ spinning_top = "0.3" [dev-dependencies] rand = "0.8" + +[features] +all-one-shot = [] diff --git a/src/lib.rs b/src/lib.rs index 01d8583..d2d5fc0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -92,6 +92,7 @@ #![warn(unsafe_op_in_unsafe_fn)] pub(crate) mod mutex; +#[cfg(not(feature = "all-one-shot"))] pub(crate) mod rwlock { /// A simple spinning, read-preferring readers-writer lock with exponential backoff. pub type RawRwSpinLock = spinning_top::RawRwSpinlock; @@ -109,6 +110,14 @@ pub(crate) mod rwlock { /// A [`lock_api::RwLockWriteGuard`] based on [`RawRwSpinLock`]. pub type RwSpinLockWriteGuard<'a, T> = lock_api::RwLockWriteGuard<'a, RawRwSpinLock, T>; } +#[cfg(feature = "all-one-shot")] +pub(crate) mod rwlock { + pub use one_shot_mutex::{ + OneShotRwLock as RwSpinLock, OneShotRwLockReadGuard as RwSpinLockReadGuard, + OneShotRwLockUpgradableReadGuard as RwSpinLockUpgradableReadGuard, + OneShotRwLockWriteGuard as RwSpinLockWriteGuard, RawOneShotRwLock as RawRwSpinLock, + }; +} pub use exclusive_cell::{CallOnce, CallOnceError, ExclusiveCell}; pub use interrupt_mutex::{InterruptMutex, InterruptMutexGuard, RawInterruptMutex}; diff --git a/src/mutex/mod.rs b/src/mutex/mod.rs index 9d3bcce..62f301c 100644 --- a/src/mutex/mod.rs +++ b/src/mutex/mod.rs @@ -1,3 +1,4 @@ +#[cfg(not(feature = "all-one-shot"))] pub(crate) mod spin { /// A simple spinlock with exponential backoff. pub type RawSpinMutex = spinning_top::RawSpinlock; @@ -8,7 +9,22 @@ pub(crate) mod spin { /// A [`lock_api::MutexGuard`] based on [`RawSpinMutex`]. pub type SpinMutexGuard<'a, T> = lock_api::MutexGuard<'a, RawSpinMutex, T>; } +#[cfg(feature = "all-one-shot")] +pub(crate) mod spin { + pub use one_shot_mutex::{ + OneShotMutex as SpinMutex, OneShotMutexGuard as SpinMutexGuard, + RawOneShotMutex as RawSpinMutex, + }; +} +#[cfg(not(feature = "all-one-shot"))] pub(crate) mod ticket; +#[cfg(feature = "all-one-shot")] +pub(crate) mod ticket { + pub use one_shot_mutex::{ + OneShotMutex as TicketMutex, OneShotMutexGuard as TicketMutexGuard, + RawOneShotMutex as RawTicketMutex, + }; +} use interrupt_mutex::RawInterruptMutex; use one_shot_mutex::RawOneShotMutex;