Skip to content

Commit

Permalink
feat: add all-one-shot feature
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 0de1978 commit 59f3051
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,6 @@ spinning_top = "0.3"

[dev-dependencies]
rand = "0.8"

[features]
all-one-shot = []
9 changes: 9 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<spinning_top::relax::Backoff>;
Expand All @@ -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};
Expand Down
16 changes: 16 additions & 0 deletions src/mutex/mod.rs
Original file line number Diff line number Diff line change
@@ -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<spinning_top::relax::Backoff>;
Expand All @@ -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;
Expand Down

0 comments on commit 59f3051

Please sign in to comment.