Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
- run: cargo check --all-targets
- run: cargo check --all-targets --features stats
- run: cargo check --all-targets --no-default-features
- run: cargo check --all-targets --no-default-features --features crossbeam
- run: cargo check --all-targets --no-default-features --features sharded-lock
- run: cargo check --all-targets --features shuttle

test:
Expand All @@ -44,7 +44,7 @@ jobs:
override: true
- run: cargo test
- run: cargo test --no-default-features
- run: cargo test --no-default-features --features crossbeam
- run: cargo test --no-default-features --features sharded-lock
# no run because of shuttle feature and non-shuttle tests
- run: cargo test --features shuttle --no-run

Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ rust-version = "1.71"

[features]
default = ["ahash", "parking_lot"]
crossbeam = ["dep:crossbeam-utils"]
sharded-lock = ["dep:crossbeam-utils"]
shuttle = ["dep:shuttle"]
stats = []

Expand Down
12 changes: 6 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,25 +66,25 @@
//! # Synchronization primitives
//!
//! By default the crate uses [parking_lot](https://crates.io/crates/parking_lot), which is enabled (by default) via
//! a crate feature with the same name. If `parking_lot` is disabled and `crossbeam` is enabled, the crate uses
//! a crate feature with the same name. If `parking_lot` is disabled and `sharded-lock` is enabled, the crate uses
//! [`crossbeam_utils::sync::ShardedLock`](https://docs.rs/crossbeam-utils/latest/crossbeam_utils/sync/struct.ShardedLock.html)
//! from [crossbeam-utils](https://crates.io/crates/crossbeam-utils) instead. If both are disabled the crate defaults
//! to the std lib implementation. The `parking_lot` and `crossbeam` features are mutually exclusive.
//! to the std lib implementation. The `parking_lot` and `sharded-lock` features are mutually exclusive.
//!
//! # Cargo Features
//!
//! | Feature | Default | Description |
//! |---------|---------|-------------|
//! | `ahash` | ✓ | Use [ahash](https://crates.io/crates/ahash) as the default hasher. When disabled, falls back to std lib's `RandomState` (currently SipHash-1-3). |
//! | `parking_lot` | ✓ | Use [parking_lot](https://crates.io/crates/parking_lot) for synchronization primitives. Mutually exclusive with `crossbeam`. |
//! | `crossbeam` | | Use [`crossbeam_utils::sync::ShardedLock`](https://docs.rs/crossbeam-utils/latest/crossbeam_utils/sync/struct.ShardedLock.html) for synchronization primitives. Mutually exclusive with `parking_lot`. |
//! | `parking_lot` | ✓ | Use [parking_lot](https://crates.io/crates/parking_lot) for synchronization primitives. Mutually exclusive with `sharded-lock`. |
//! | `sharded-lock` | | Use [`crossbeam_utils::sync::ShardedLock`](https://docs.rs/crossbeam-utils/latest/crossbeam_utils/sync/struct.ShardedLock.html) for synchronization primitives. Mutually exclusive with `parking_lot`. |
//! | `shuttle` | | Enable [shuttle](https://crates.io/crates/shuttle) testing support for concurrency testing. |
//! | `stats` | | Enable cache statistics tracking via the `hits()` and `misses()` methods. |
#![allow(clippy::type_complexity)]
#![cfg_attr(docsrs, feature(doc_cfg))]

#[cfg(all(feature = "parking_lot", feature = "crossbeam"))]
compile_error!("features `parking_lot` and `crossbeam` are mutually exclusive");
#[cfg(all(feature = "parking_lot", feature = "sharded-lock"))]
compile_error!("features `parking_lot` and `sharded-lock` are mutually exclusive");

#[cfg(not(fuzzing))]
mod linked_slab;
Expand Down
16 changes: 8 additions & 8 deletions src/rw_lock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,23 @@ use std::ops::{Deref, DerefMut};

#[cfg(feature = "parking_lot")]
type InnerRwLock<T> = parking_lot::RwLock<T>;
#[cfg(all(not(feature = "parking_lot"), feature = "crossbeam"))]
#[cfg(all(not(feature = "parking_lot"), feature = "sharded-lock"))]
type InnerRwLock<T> = crossbeam_utils::sync::ShardedLock<T>;
#[cfg(all(not(feature = "parking_lot"), not(feature = "crossbeam")))]
#[cfg(all(not(feature = "parking_lot"), not(feature = "sharded-lock")))]
type InnerRwLock<T> = std::sync::RwLock<T>;

#[cfg(feature = "parking_lot")]
type InnerRwLockReadGuard<'rwlock, T> = parking_lot::RwLockReadGuard<'rwlock, T>;
#[cfg(all(not(feature = "parking_lot"), feature = "crossbeam"))]
#[cfg(all(not(feature = "parking_lot"), feature = "sharded-lock"))]
type InnerRwLockReadGuard<'rwlock, T> = crossbeam_utils::sync::ShardedLockReadGuard<'rwlock, T>;
#[cfg(all(not(feature = "parking_lot"), not(feature = "crossbeam")))]
#[cfg(all(not(feature = "parking_lot"), not(feature = "sharded-lock")))]
type InnerRwLockReadGuard<'rwlock, T> = std::sync::RwLockReadGuard<'rwlock, T>;

#[cfg(feature = "parking_lot")]
type InnerRwLockWriteGuard<'rwlock, T> = parking_lot::RwLockWriteGuard<'rwlock, T>;
#[cfg(all(not(feature = "parking_lot"), feature = "crossbeam"))]
#[cfg(all(not(feature = "parking_lot"), feature = "sharded-lock"))]
type InnerRwLockWriteGuard<'rwlock, T> = crossbeam_utils::sync::ShardedLockWriteGuard<'rwlock, T>;
#[cfg(all(not(feature = "parking_lot"), not(feature = "crossbeam")))]
#[cfg(all(not(feature = "parking_lot"), not(feature = "sharded-lock")))]
type InnerRwLockWriteGuard<'rwlock, T> = std::sync::RwLockWriteGuard<'rwlock, T>;

/// A reader-writer lock.
Expand Down Expand Up @@ -58,15 +58,15 @@ pub struct RwLockReadGuard<'rwlock, T: ?Sized>(InnerRwLockReadGuard<'rwlock, T>)
#[must_use = "if unused the RwLock will immediately unlock"]
pub struct RwLockWriteGuard<'rwlock, T: ?Sized>(InnerRwLockWriteGuard<'rwlock, T>);

#[cfg(not(feature = "crossbeam"))]
#[cfg(not(feature = "sharded-lock"))]
impl<T> RwLock<T> {
/// Creates a new instance of an `RwLock<T>` which is unlocked.
pub const fn new(t: T) -> Self {
Self(InnerRwLock::new(t))
}
}

#[cfg(feature = "crossbeam")]
#[cfg(feature = "sharded-lock")]
impl<T> RwLock<T> {
/// Creates a new instance of an `RwLock<T>` which is unlocked.
pub fn new(t: T) -> Self {
Expand Down
Loading