diff options
| author | Mica White <botahamec@outlook.com> | 2024-03-10 19:40:23 -0400 |
|---|---|---|
| committer | Mica White <botahamec@outlook.com> | 2024-03-10 19:40:23 -0400 |
| commit | e8d25c9e6e7d5c3a5a14219fc77ea98760cef790 (patch) | |
| tree | 9436371726e0250ad38d33fa24fbf33271d4ec13 | |
| parent | 0c519b6c7801aa6a085551c8e144f0336e615870 (diff) | |
Make spin and parking lot optional
| -rw-r--r-- | Cargo.toml | 7 | ||||
| -rw-r--r-- | src/lib.rs | 4 | ||||
| -rw-r--r-- | src/mutex.rs | 2 | ||||
| -rw-r--r-- | src/rwlock.rs | 2 |
4 files changed, 13 insertions, 2 deletions
@@ -17,5 +17,8 @@ categories = ["concurrency"] thread_local = "1" once_cell = "1" lock_api = "0.4" -parking_lot = "0.12" -spin = "0.9" +parking_lot = { version = "0.12", optional = true } +spin = { version = "0.9", optional = true } + +[features] +default = ["parking_lot"] @@ -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<T> = mutex::Mutex<T, parking_lot::RawMutex>; /// A reader-writer lock /// /// By default, this uses `parking_lot` as a backend. +#[cfg(feature = "parking_lot")] pub type RwLock<T> = rwlock::RwLock<T, parking_lot::RawRwLock>; 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<T> = Mutex<T, spin::Mutex<()>>; /// A parking lot mutex +#[cfg(feature = "parking_lot")] pub type ParkingMutex<T> = Mutex<T, parking_lot::RawMutex>; /// 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<T> = RwLock<T, spin::RwLock<()>>; +#[cfg(feature = "parking_lot")] pub type ParkingRwLock<T> = RwLock<T, parking_lot::RawRwLock>; pub struct RwLock<T: ?Sized, R> { |
