diff options
| author | bors <bors@rust-lang.org> | 2022-05-06 14:53:24 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2022-05-06 14:53:24 +0000 |
| commit | e209e85e39b4851c3ec122a45ddeabe318b2d522 (patch) | |
| tree | e5089db5d51b424ee8d297d4b6053dc8a81a802c | |
| parent | 9a251644fa2adde5f46eea8d342b7e60e4716039 (diff) | |
| parent | 7e9303272695b04c6c84a63aa447fa572c768f13 (diff) | |
| download | rust-e209e85e39b4851c3ec122a45ddeabe318b2d522.tar.gz rust-e209e85e39b4851c3ec122a45ddeabe318b2d522.zip | |
Auto merge of #95183 - ibraheemdev:arc-count-acquire, r=Amanieu
Weaken needlessly restrictive orderings on `Arc::*_count` There is no apparent reason for these to be `SeqCst`. For reference, [the Boost C++ implementation relies on acquire semantics](https://github.com/boostorg/smart_ptr/blob/f2cc84a23c64b8a73c9b72b34799d0854d7e0787/include/boost/smart_ptr/detail/sp_counted_base_std_atomic.hpp#L137-L140).
| -rw-r--r-- | library/alloc/src/sync.rs | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/library/alloc/src/sync.rs b/library/alloc/src/sync.rs index 2bd8f418ee9..06aecd9cc1e 100644 --- a/library/alloc/src/sync.rs +++ b/library/alloc/src/sync.rs @@ -25,7 +25,7 @@ use core::ptr::{self, NonNull}; #[cfg(not(no_global_oom_handling))] use core::slice::from_raw_parts_mut; use core::sync::atomic; -use core::sync::atomic::Ordering::{Acquire, Relaxed, Release, SeqCst}; +use core::sync::atomic::Ordering::{Acquire, Relaxed, Release}; #[cfg(not(no_global_oom_handling))] use crate::alloc::handle_alloc_error; @@ -984,7 +984,7 @@ impl<T: ?Sized> Arc<T> { #[must_use] #[stable(feature = "arc_counts", since = "1.15.0")] pub fn weak_count(this: &Self) -> usize { - let cnt = this.inner().weak.load(SeqCst); + let cnt = this.inner().weak.load(Acquire); // If the weak count is currently locked, the value of the // count was 0 just before taking the lock. if cnt == usize::MAX { 0 } else { cnt - 1 } @@ -1014,7 +1014,7 @@ impl<T: ?Sized> Arc<T> { #[must_use] #[stable(feature = "arc_counts", since = "1.15.0")] pub fn strong_count(this: &Self) -> usize { - this.inner().strong.load(SeqCst) + this.inner().strong.load(Acquire) } /// Increments the strong reference count on the `Arc<T>` associated with the @@ -1976,7 +1976,7 @@ impl<T: ?Sized> Weak<T> { #[must_use] #[stable(feature = "weak_counts", since = "1.41.0")] pub fn strong_count(&self) -> usize { - if let Some(inner) = self.inner() { inner.strong.load(SeqCst) } else { 0 } + if let Some(inner) = self.inner() { inner.strong.load(Acquire) } else { 0 } } /// Gets an approximation of the number of `Weak` pointers pointing to this @@ -1995,8 +1995,8 @@ impl<T: ?Sized> Weak<T> { pub fn weak_count(&self) -> usize { self.inner() .map(|inner| { - let weak = inner.weak.load(SeqCst); - let strong = inner.strong.load(SeqCst); + let weak = inner.weak.load(Acquire); + let strong = inner.strong.load(Acquire); if strong == 0 { 0 } else { |
