summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.toml7
-rw-r--r--src/lib.rs4
-rw-r--r--src/mutex.rs2
-rw-r--r--src/rwlock.rs2
4 files changed, 13 insertions, 2 deletions
diff --git a/Cargo.toml b/Cargo.toml
index 1b0525b..45020c2 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -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"]
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<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> {