From f94c60944c15196fdc788c7f6f30c3416fe2af18 Mon Sep 17 00:00:00 2001 From: Seth Westphal Date: Mon, 22 Jan 2024 17:19:28 -0600 Subject: [PATCH 1/7] Update dependencies. --- benchmark/Cargo.toml | 2 +- core/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/benchmark/Cargo.toml b/benchmark/Cargo.toml index 9cd06cb2..11e87c4b 100644 --- a/benchmark/Cargo.toml +++ b/benchmark/Cargo.toml @@ -6,7 +6,7 @@ edition = "2018" [dependencies] parking_lot = {path = ".."} -seqlock = "0.1" +seqlock = "0.2" libc = "0.2" [[bin]] diff --git a/core/Cargo.toml b/core/Cargo.toml index a899fc56..ebdccffc 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -27,7 +27,7 @@ libc = "0.2.95" redox_syscall = "0.4" [target.'cfg(windows)'.dependencies] -windows-targets = "0.48.0" +windows-targets = "0.52.0" [features] nightly = [] From 4edb72b891fb3d8514a7f44446f0c6acf2844abd Mon Sep 17 00:00:00 2001 From: Seth Westphal Date: Thu, 25 Jan 2024 18:58:24 -0600 Subject: [PATCH 2/7] Bump MSRV to 1.56. --- .github/workflows/rust.yml | 6 +++--- Cargo.toml | 4 ++-- README.md | 2 +- benchmark/Cargo.toml | 2 +- core/Cargo.toml | 4 ++-- lock_api/Cargo.toml | 4 ++-- 6 files changed, 11 insertions(+), 11 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 1e29635d..7b791ee2 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -17,14 +17,14 @@ jobs: strategy: matrix: os: [ubuntu, macos, windows] - channel: [1.49.0, stable, beta, nightly] + channel: [1.56.0, stable, beta, nightly] feature: [arc_lock, serde, deadlock_detection] exclude: - feature: deadlock_detection - channel: '1.49.0' + channel: '1.56.0' # Versions before 1.54 fail to build on the latest XCode. - os: macos - channel: '1.49.0' + channel: '1.56.0' include: - channel: nightly feature: nightly diff --git a/Cargo.toml b/Cargo.toml index bc41f367..5dccf7b8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,8 +8,8 @@ repository = "https://github.com/Amanieu/parking_lot" readme = "README.md" keywords = ["mutex", "condvar", "rwlock", "once", "thread"] categories = ["concurrency"] -edition = "2018" -rust-version = "1.49" +edition = "2021" +rust-version = "1.56" [package.metadata.docs.rs] features = ["arc_lock", "serde", "deadlock_detection"] diff --git a/README.md b/README.md index b5afdd81..c5290ccd 100644 --- a/README.md +++ b/README.md @@ -132,7 +132,7 @@ changes to the core API do not cause breaking changes for users of `parking_lot` ## Minimum Rust version -The current minimum required Rust version is 1.49. Any change to this is +The current minimum required Rust version is 1.56. Any change to this is considered a breaking change and will require a major version bump. ## License diff --git a/benchmark/Cargo.toml b/benchmark/Cargo.toml index 11e87c4b..c470b5d5 100644 --- a/benchmark/Cargo.toml +++ b/benchmark/Cargo.toml @@ -2,7 +2,7 @@ name = "parking_lot-benchmark" version = "0.0.0" authors = ["Amanieu d'Antras "] -edition = "2018" +edition = "2021" [dependencies] parking_lot = {path = ".."} diff --git a/core/Cargo.toml b/core/Cargo.toml index ebdccffc..31ac4df4 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -7,8 +7,8 @@ license = "MIT OR Apache-2.0" repository = "https://github.com/Amanieu/parking_lot" keywords = ["mutex", "condvar", "rwlock", "once", "thread"] categories = ["concurrency"] -edition = "2018" -rust-version = "1.49.0" +edition = "2021" +rust-version = "1.56.0" [package.metadata.docs.rs] rustdoc-args = ["--generate-link-to-definition"] diff --git a/lock_api/Cargo.toml b/lock_api/Cargo.toml index 683e69fe..47b4baf6 100644 --- a/lock_api/Cargo.toml +++ b/lock_api/Cargo.toml @@ -7,8 +7,8 @@ license = "MIT OR Apache-2.0" repository = "https://github.com/Amanieu/parking_lot" keywords = ["mutex", "rwlock", "lock", "no_std"] categories = ["concurrency", "no-std"] -edition = "2018" -rust-version = "1.49.0" +edition = "2021" +rust-version = "1.56.0" [package.metadata.docs.rs] all-features = true From df187db83ed2d61e27001401585b2e6c2f2c3d3c Mon Sep 17 00:00:00 2001 From: Seth Westphal Date: Thu, 25 Jan 2024 18:58:42 -0600 Subject: [PATCH 3/7] cargo fmt --- core/src/thread_parker/unix.rs | 21 ++++++++++++++++++--- src/remutex.rs | 2 +- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/core/src/thread_parker/unix.rs b/core/src/thread_parker/unix.rs index fdc1ed93..329cddce 100644 --- a/core/src/thread_parker/unix.rs +++ b/core/src/thread_parker/unix.rs @@ -5,7 +5,12 @@ // http://opensource.org/licenses/MIT>, at your option. This file may not be // copied, modified, or distributed except according to those terms. -#[cfg(any(target_os = "macos", target_os = "tvos", target_os = "ios", target_os = "watchos"))] +#[cfg(any( + target_os = "macos", + target_os = "tvos", + target_os = "ios", + target_os = "watchos" +))] use core::ptr; use core::{ cell::{Cell, UnsafeCell}, @@ -197,7 +202,12 @@ impl super::UnparkHandleT for UnparkHandle { } // Returns the current time on the clock used by pthread_cond_t as a timespec. -#[cfg(any(target_os = "macos", target_os = "ios", target_os = "tvos", target_os = "watchos"))] +#[cfg(any( + target_os = "macos", + target_os = "ios", + target_os = "tvos", + target_os = "watchos" +))] #[inline] fn timespec_now() -> libc::timespec { let mut now = MaybeUninit::::uninit(); @@ -210,7 +220,12 @@ fn timespec_now() -> libc::timespec { tv_nsec: now.tv_usec as tv_nsec_t * 1000, } } -#[cfg(not(any(target_os = "macos", target_os = "ios", target_os = "tvos", target_os = "watchos")))] +#[cfg(not(any( + target_os = "macos", + target_os = "ios", + target_os = "tvos", + target_os = "watchos" +)))] #[inline] fn timespec_now() -> libc::timespec { let mut now = MaybeUninit::::uninit(); diff --git a/src/remutex.rs b/src/remutex.rs index 155ec187..6b61b91c 100644 --- a/src/remutex.rs +++ b/src/remutex.rs @@ -73,9 +73,9 @@ mod tests { use crate::ReentrantMutex; use crate::ReentrantMutexGuard; use std::cell::RefCell; + use std::sync::mpsc::channel; use std::sync::Arc; use std::thread; - use std::sync::mpsc::channel; #[cfg(feature = "serde")] use bincode::{deserialize, serialize}; From 73d621619b8aae7ebfaa599f4881bf728cde5eac Mon Sep 17 00:00:00 2001 From: Seth Westphal Date: Thu, 25 Jan 2024 19:01:11 -0600 Subject: [PATCH 4/7] clippy --- src/condvar.rs | 18 +++++++++--------- src/mutex.rs | 4 ++-- src/raw_rwlock.rs | 30 ++++++++++++------------------ 3 files changed, 23 insertions(+), 29 deletions(-) diff --git a/src/condvar.rs b/src/condvar.rs index ea55ad39..7818a14c 100644 --- a/src/condvar.rs +++ b/src/condvar.rs @@ -565,7 +565,7 @@ mod tests { let data = data.clone(); let tx = tx.clone(); thread::spawn(move || { - let &(ref lock, ref cond) = &*data; + let (lock, cond) = &*data; let mut cnt = lock.lock(); *cnt += 1; if *cnt == N { @@ -579,7 +579,7 @@ mod tests { } drop(tx); - let &(ref lock, ref cond) = &*data; + let (lock, cond) = &*data; rx.recv().unwrap(); let mut cnt = lock.lock(); *cnt = 0; @@ -627,7 +627,7 @@ mod tests { let data = data.clone(); let tx = tx.clone(); thread::spawn(move || { - let &(ref lock, ref cond) = &*data; + let (lock, cond) = &*data; let mut cnt = lock.lock(); *cnt += 1; if *cnt == N { @@ -641,7 +641,7 @@ mod tests { } drop(tx); - let &(ref lock, ref cond) = &*data; + let (lock, cond) = &*data; rx.recv().unwrap(); let mut cnt = lock.lock(); *cnt = 0; @@ -832,7 +832,7 @@ mod tests { drop(g); rx.recv().unwrap(); let _g = m.lock(); - let _guard = PanicGuard(&*c); + let _guard = PanicGuard(&c); c.wait(&mut m3.lock()); } @@ -1054,7 +1054,7 @@ mod webkit_queue_test { let (should_notify, result) = { let mut queue = input_queue.lock(); wait( - &*empty_condition, + &empty_condition, &mut queue, |state| -> bool { !state.items.is_empty() || !state.should_continue }, &timeout, @@ -1067,7 +1067,7 @@ mod webkit_queue_test { std::mem::drop(queue); (should_notify, result) }; - notify(notify_style, &*full_condition, should_notify); + notify(notify_style, &full_condition, should_notify); if let Some(result) = result { output_queue.lock().push(result); @@ -1089,7 +1089,7 @@ mod webkit_queue_test { let should_notify = { let mut queue = queue.lock(); wait( - &*full_condition, + &full_condition, &mut queue, |state| state.items.len() < max_queue_size, &timeout, @@ -1099,7 +1099,7 @@ mod webkit_queue_test { std::mem::drop(queue); should_notify }; - notify(notify_style, &*empty_condition, should_notify); + notify(notify_style, &empty_condition, should_notify); } }) } diff --git a/src/mutex.rs b/src/mutex.rs index 35f97a91..ac953127 100644 --- a/src/mutex.rs +++ b/src/mutex.rs @@ -215,13 +215,13 @@ mod tests { let _t = thread::spawn(move || { // wait until parent gets in rx.recv().unwrap(); - let &(ref lock, ref cvar) = &*packet2.0; + let (lock, cvar) = &*packet2.0; let mut lock = lock.lock(); *lock = true; cvar.notify_one(); }); - let &(ref lock, ref cvar) = &*packet.0; + let (lock, cvar) = &*packet.0; let mut lock = lock.lock(); tx.send(()).unwrap(); assert!(!*lock); diff --git a/src/raw_rwlock.rs b/src/raw_rwlock.rs index e15eabf1..62dce513 100644 --- a/src/raw_rwlock.rs +++ b/src/raw_rwlock.rs @@ -346,8 +346,8 @@ unsafe impl lock_api::RawRwLockUpgrade for RawRwLock { unsafe fn unlock_upgradable(&self) { self.deadlock_release(); let state = self.state.load(Ordering::Relaxed); - if state & PARKED_BIT == 0 { - if self + if state & PARKED_BIT == 0 + && self .state .compare_exchange_weak( state, @@ -356,9 +356,8 @@ unsafe impl lock_api::RawRwLockUpgrade for RawRwLock { Ordering::Relaxed, ) .is_ok() - { - return; - } + { + return; } self.unlock_upgradable_slow(false); } @@ -399,8 +398,8 @@ unsafe impl lock_api::RawRwLockUpgradeFair for RawRwLock { unsafe fn unlock_upgradable_fair(&self) { self.deadlock_release(); let state = self.state.load(Ordering::Relaxed); - if state & PARKED_BIT == 0 { - if self + if state & PARKED_BIT == 0 + && self .state .compare_exchange_weak( state, @@ -409,9 +408,8 @@ unsafe impl lock_api::RawRwLockUpgradeFair for RawRwLock { Ordering::Relaxed, ) .is_ok() - { - return; - } + { + return; } self.unlock_upgradable_slow(false); } @@ -540,10 +538,8 @@ impl RawRwLock { let mut state = self.state.load(Ordering::Relaxed); loop { // This mirrors the condition in try_lock_shared_fast - if state & WRITER_BIT != 0 { - if !recursive || state & READERS_MASK == 0 { - return false; - } + if state & WRITER_BIT != 0 && (!recursive || state & READERS_MASK == 0) { + return false; } if have_elision() && state == 0 { match self.state.elision_compare_exchange_acquire(0, ONE_READER) { @@ -688,10 +684,8 @@ impl RawRwLock { } // This is the same condition as try_lock_shared_fast - if *state & WRITER_BIT != 0 { - if !recursive || *state & READERS_MASK == 0 { - return false; - } + if *state & WRITER_BIT != 0 && (!recursive || *state & READERS_MASK == 0) { + return false; } if self From a5b30ac728528e595539a82194edcf42805d251e Mon Sep 17 00:00:00 2001 From: Seth Westphal Date: Thu, 25 Jan 2024 19:02:04 -0600 Subject: [PATCH 5/7] clippy --- src/once.rs | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/once.rs b/src/once.rs index 6b91ac4a..ed05a522 100644 --- a/src/once.rs +++ b/src/once.rs @@ -40,20 +40,14 @@ impl OnceState { /// indicate to future forced initialization routines that it is poisoned. #[inline] pub fn poisoned(self) -> bool { - match self { - OnceState::Poisoned => true, - _ => false, - } + matches!(self, OnceState::Poisoned) } /// Returns whether the associated `Once` has successfully executed a /// closure. #[inline] pub fn done(self) -> bool { - match self { - OnceState::Done => true, - _ => false, - } + matches!(self, OnceState::Done) } } From e2a134453acff1e702c455fc57e197982bd1ef81 Mon Sep 17 00:00:00 2001 From: Seth Westphal Date: Mon, 29 Jan 2024 17:02:01 -0600 Subject: [PATCH 6/7] Revert clippy fixes to match owner preference. --- src/raw_rwlock.rs | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/src/raw_rwlock.rs b/src/raw_rwlock.rs index 62dce513..79614de3 100644 --- a/src/raw_rwlock.rs +++ b/src/raw_rwlock.rs @@ -346,8 +346,9 @@ unsafe impl lock_api::RawRwLockUpgrade for RawRwLock { unsafe fn unlock_upgradable(&self) { self.deadlock_release(); let state = self.state.load(Ordering::Relaxed); - if state & PARKED_BIT == 0 - && self + #[allow(clippy::collapsible_if)] + if state & PARKED_BIT == 0 { + if self .state .compare_exchange_weak( state, @@ -356,9 +357,11 @@ unsafe impl lock_api::RawRwLockUpgrade for RawRwLock { Ordering::Relaxed, ) .is_ok() - { - return; + { + return; + } } + self.unlock_upgradable_slow(false); } @@ -398,8 +401,9 @@ unsafe impl lock_api::RawRwLockUpgradeFair for RawRwLock { unsafe fn unlock_upgradable_fair(&self) { self.deadlock_release(); let state = self.state.load(Ordering::Relaxed); - if state & PARKED_BIT == 0 - && self + #[allow(clippy::collapsible_if)] + if state & PARKED_BIT == 0 { + if self .state .compare_exchange_weak( state, @@ -408,8 +412,9 @@ unsafe impl lock_api::RawRwLockUpgradeFair for RawRwLock { Ordering::Relaxed, ) .is_ok() - { - return; + { + return; + } } self.unlock_upgradable_slow(false); } @@ -538,8 +543,11 @@ impl RawRwLock { let mut state = self.state.load(Ordering::Relaxed); loop { // This mirrors the condition in try_lock_shared_fast - if state & WRITER_BIT != 0 && (!recursive || state & READERS_MASK == 0) { - return false; + #[allow(clippy::collapsible_if)] + if state & WRITER_BIT != 0 { + if !recursive || state & READERS_MASK == 0 { + return false; + } } if have_elision() && state == 0 { match self.state.elision_compare_exchange_acquire(0, ONE_READER) { @@ -684,8 +692,11 @@ impl RawRwLock { } // This is the same condition as try_lock_shared_fast - if *state & WRITER_BIT != 0 && (!recursive || *state & READERS_MASK == 0) { - return false; + #[allow(clippy::collapsible_if)] + if *state & WRITER_BIT != 0 { + if !recursive || *state & READERS_MASK == 0 { + return false; + } } if self From 70459b9442dc70363f59d1d2da817f9c7a42087f Mon Sep 17 00:00:00 2001 From: Seth Westphal Date: Mon, 29 Jan 2024 17:05:06 -0600 Subject: [PATCH 7/7] Remove newline. --- src/raw_rwlock.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/raw_rwlock.rs b/src/raw_rwlock.rs index 79614de3..599889b1 100644 --- a/src/raw_rwlock.rs +++ b/src/raw_rwlock.rs @@ -361,7 +361,6 @@ unsafe impl lock_api::RawRwLockUpgrade for RawRwLock { return; } } - self.unlock_upgradable_slow(false); }