From e8d25c9e6e7d5c3a5a14219fc77ea98760cef790 Mon Sep 17 00:00:00 2001 From: Mica White Date: Sun, 10 Mar 2024 19:40:23 -0400 Subject: Make spin and parking lot optional --- src/lib.rs | 4 ++++ src/mutex.rs | 2 ++ src/rwlock.rs | 2 ++ 3 files changed, 8 insertions(+) (limited to 'src') diff --git a/src/lib.rs b/src/lib.rs index e99db7c..f51adb2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -13,6 +13,8 @@ pub mod rwlock; pub use collection::LockCollection; pub use lockable::Lockable; + +#[cfg(feature = "spin")] pub use mutex::SpinLock; /// The key for the current thread. @@ -24,9 +26,11 @@ pub type ThreadKey = key::Key<'static>; /// A mutual exclusion primitive useful for protecting shared data, which cannot deadlock. /// /// By default, this uses `parking_lot` as a backend. +#[cfg(feature = "parking_lot")] pub type Mutex = mutex::Mutex; /// A reader-writer lock /// /// By default, this uses `parking_lot` as a backend. +#[cfg(feature = "parking_lot")] pub type RwLock = rwlock::RwLock; diff --git a/src/mutex.rs b/src/mutex.rs index e7a439c..0d67f33 100644 --- a/src/mutex.rs +++ b/src/mutex.rs @@ -8,9 +8,11 @@ use lock_api::RawMutex; use crate::key::Keyable; /// A spinning mutex +#[cfg(feature = "spin")] pub type SpinLock = Mutex>; /// A parking lot mutex +#[cfg(feature = "parking_lot")] pub type ParkingMutex = Mutex; /// A mutual exclusion primitive useful for protecting shared data, which diff --git a/src/rwlock.rs b/src/rwlock.rs index f5f0f2b..259c247 100644 --- a/src/rwlock.rs +++ b/src/rwlock.rs @@ -7,8 +7,10 @@ use lock_api::RawRwLock; use crate::key::Keyable; +#[cfg(feature = "spin")] pub type SpinRwLock = RwLock>; +#[cfg(feature = "parking_lot")] pub type ParkingRwLock = RwLock; pub struct RwLock { -- cgit v1.2.3