Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Initial (optional) triomphe::Arc support #454

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ features = ["arc_lock", "serde", "deadlock_detection"]
[dependencies]
parking_lot_core = { path = "core", version = "0.9.0" }
lock_api = { path = "lock_api", version = "0.4.6" }
triomphe = { version = "0.1.14", optional = true }

[dev-dependencies]
rand = "0.8.3"
Expand All @@ -37,6 +38,7 @@ deadlock_detection = ["parking_lot_core/deadlock_detection"]
serde = ["lock_api/serde"]
send_guard = []
hardware-lock-elision = []
triomphe = ["dep:triomphe", "lock_api/triomphe"]

[workspace]
exclude = ["benchmark"]
2 changes: 2 additions & 0 deletions lock_api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ rustdoc-args = ["--cfg", "docsrs", "--generate-link-to-definition"]
[dependencies]
scopeguard = { version = "1.1.0", default-features = false }
owning_ref = { version = "0.4.1", optional = true }
triomphe = { version = "0.1.14", optional = true }

# Optional dependency for supporting serde. Optional crates automatically
# create a feature with the same name as the crate, so if you need serde
Expand All @@ -31,3 +32,4 @@ default = ["atomic_usize"]
nightly = []
arc_lock = []
atomic_usize = []
triomphe = ["dep:triomphe"]
8 changes: 7 additions & 1 deletion lock_api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,18 @@
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
#![warn(missing_docs)]
#![warn(rust_2018_idioms)]
#![cfg_attr(
all(feature = "arc_lock", feature = "triomphe"),
feature(arbitrary_self_types)
)]

#[macro_use]
extern crate scopeguard;

#[cfg(feature = "arc_lock")]
#[cfg(all(feature = "arc_lock", not(feature = "triomphe")))]
extern crate alloc;
#[cfg(all(feature = "arc_lock", feature = "triomphe"))]
extern crate triomphe;

/// Marker type which indicates that the Guard type for a lock is `Send`.
pub struct GuardSend(());
Expand Down
4 changes: 3 additions & 1 deletion lock_api/src/mutex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ use core::marker::PhantomData;
use core::mem;
use core::ops::{Deref, DerefMut};

#[cfg(feature = "arc_lock")]
#[cfg(all(feature = "arc_lock", not(feature = "triomphe")))]
use alloc::sync::Arc;
#[cfg(feature = "arc_lock")]
use core::mem::ManuallyDrop;
#[cfg(feature = "arc_lock")]
use core::ptr;
#[cfg(all(feature = "arc_lock", feature = "triomphe"))]
use triomphe::Arc;

#[cfg(feature = "owning_ref")]
use owning_ref::StableAddress;
Expand Down
4 changes: 3 additions & 1 deletion lock_api/src/remutex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@ use core::{
sync::atomic::{AtomicUsize, Ordering},
};

#[cfg(feature = "arc_lock")]
#[cfg(all(feature = "arc_lock", not(feature = "triomphe")))]
use alloc::sync::Arc;
#[cfg(feature = "arc_lock")]
use core::mem::ManuallyDrop;
#[cfg(feature = "arc_lock")]
use core::ptr;
#[cfg(all(feature = "arc_lock", feature = "triomphe"))]
use triomphe::Arc;

#[cfg(feature = "owning_ref")]
use owning_ref::StableAddress;
Expand Down
4 changes: 3 additions & 1 deletion lock_api/src/rwlock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ use core::marker::PhantomData;
use core::mem;
use core::ops::{Deref, DerefMut};

#[cfg(feature = "arc_lock")]
#[cfg(all(feature = "arc_lock", not(feature = "triomphe")))]
use alloc::sync::Arc;
#[cfg(feature = "arc_lock")]
use core::mem::ManuallyDrop;
#[cfg(feature = "arc_lock")]
use core::ptr;
#[cfg(all(feature = "arc_lock", feature = "triomphe"))]
use triomphe::Arc;

#[cfg(feature = "owning_ref")]
use owning_ref::StableAddress;
Expand Down
9 changes: 8 additions & 1 deletion src/condvar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -526,12 +526,15 @@ impl fmt::Debug for Condvar {
mod tests {
use crate::{Condvar, Mutex, MutexGuard};
use std::sync::mpsc::channel;
#[cfg(not(feature = "triomphe"))]
use std::sync::Arc;
use std::thread;
use std::thread::sleep;
use std::thread::JoinHandle;
use std::time::Duration;
use std::time::Instant;
#[cfg(feature = "triomphe")]
use triomphe::Arc;

#[test]
fn smoke() {
Expand Down Expand Up @@ -916,7 +919,11 @@ mod tests {
#[cfg(test)]
mod webkit_queue_test {
use crate::{Condvar, Mutex, MutexGuard};
use std::{collections::VecDeque, sync::Arc, thread, time::Duration};
#[cfg(not(feature = "triomphe"))]
use std::sync::Arc;
use std::{collections::VecDeque, thread, time::Duration};
#[cfg(feature = "triomphe")]
use triomphe::Arc;

#[derive(Clone, Copy)]
enum Timeout {
Expand Down
3 changes: 3 additions & 0 deletions src/fair_mutex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,11 @@ mod tests {
use crate::FairMutex;
use std::sync::atomic::{AtomicUsize, Ordering};
use std::sync::mpsc::channel;
#[cfg(not(feature = "triomphe"))]
use std::sync::Arc;
use std::thread;
#[cfg(feature = "triomphe")]
use triomphe::Arc;

#[cfg(feature = "serde")]
use bincode::{deserialize, serialize};
Expand Down
3 changes: 3 additions & 0 deletions src/mutex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,11 @@ mod tests {
use crate::{Condvar, Mutex};
use std::sync::atomic::{AtomicUsize, Ordering};
use std::sync::mpsc::channel;
#[cfg(not(feature = "triomphe"))]
use std::sync::Arc;
use std::thread;
#[cfg(feature = "triomphe")]
use triomphe::Arc;

#[cfg(feature = "serde")]
use bincode::{deserialize, serialize};
Expand Down
3 changes: 3 additions & 0 deletions src/remutex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,11 @@ mod tests {
use crate::ReentrantMutexGuard;
use std::cell::RefCell;
use std::sync::mpsc::channel;
#[cfg(not(feature = "triomphe"))]
use std::sync::Arc;
use std::thread;
#[cfg(feature = "triomphe")]
use triomphe::Arc;

#[cfg(feature = "serde")]
use bincode::{deserialize, serialize};
Expand Down
10 changes: 9 additions & 1 deletion src/rwlock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,12 @@ mod tests {
use rand::Rng;
use std::sync::atomic::{AtomicUsize, Ordering};
use std::sync::mpsc::channel;
#[cfg(not(feature = "triomphe"))]
use std::sync::Arc;
use std::thread;
use std::time::Duration;
#[cfg(feature = "triomphe")]
use triomphe::Arc;

#[cfg(feature = "serde")]
use bincode::{deserialize, serialize};
Expand Down Expand Up @@ -642,7 +645,12 @@ mod tests {
#[test]
#[cfg(feature = "arc_lock")]
fn test_issue_430() {
let lock = std::sync::Arc::new(RwLock::new(0));
#[cfg(not(feature = "triomphe"))]
use std::sync::Arc;
#[cfg(feature = "triomphe")]
use triomphe::Arc;

let lock = Arc::new(RwLock::new(0));

let mut rl = lock.upgradable_read_arc();

Expand Down