diff options
| author | bors <bors@rust-lang.org> | 2023-09-30 02:15:19 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2023-09-30 02:15:19 +0000 |
| commit | 4efd65571e7ad62ca2cfb86271e7c6af192032ce (patch) | |
| tree | 7972c728e8a1e01f54f57dad22bcce4d99b1350c /library/alloc/src | |
| parent | b8b376a2877f6d3d9529a3dee9c0e2fe29147468 (diff) | |
| parent | 4c2f1c615b976fcd21f6cc2078b09d10c9d72507 (diff) | |
| download | rust-4efd65571e7ad62ca2cfb86271e7c6af192032ce.tar.gz rust-4efd65571e7ad62ca2cfb86271e7c6af192032ce.zip | |
Auto merge of #115546 - SUPERCILEX:patch-2, r=Amanieu
Weaken needlessly restrictive orderings on Arc::*_count Follow up to https://github.com/rust-lang/rust/pull/95183 from this zulip: https://rust-lang.zulipchat.com/#narrow/stream/219381-t-libs/topic/Why.20does.20Arc.3A.3Astrong_count.20use.20Acquire.20instead.20of.20Relaxed.3F/near/386213850 I'd like to use the strong_count for a lockless algorithm I'm writing, but I don't need acquire semantics so that's pointlessly restrictive on arm/risc-v.
Diffstat (limited to 'library/alloc/src')
| -rw-r--r-- | library/alloc/src/sync.rs | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/library/alloc/src/sync.rs b/library/alloc/src/sync.rs index 9df971af49c..61f4bfc54b0 100644 --- a/library/alloc/src/sync.rs +++ b/library/alloc/src/sync.rs @@ -1618,7 +1618,7 @@ impl<T: ?Sized, A: Allocator> Arc<T, A> { #[must_use] #[stable(feature = "arc_counts", since = "1.15.0")] pub fn weak_count(this: &Self) -> usize { - let cnt = this.inner().weak.load(Acquire); + let cnt = this.inner().weak.load(Relaxed); // 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 } @@ -1648,7 +1648,7 @@ impl<T: ?Sized, A: Allocator> Arc<T, A> { #[must_use] #[stable(feature = "arc_counts", since = "1.15.0")] pub fn strong_count(this: &Self) -> usize { - this.inner().strong.load(Acquire) + this.inner().strong.load(Relaxed) } /// Increments the strong reference count on the `Arc<T>` associated with the @@ -2803,7 +2803,7 @@ impl<T: ?Sized, A: Allocator> Weak<T, A> { #[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(Acquire) } else { 0 } + if let Some(inner) = self.inner() { inner.strong.load(Relaxed) } else { 0 } } /// Gets an approximation of the number of `Weak` pointers pointing to this @@ -2822,7 +2822,7 @@ impl<T: ?Sized, A: Allocator> Weak<T, A> { pub fn weak_count(&self) -> usize { if let Some(inner) = self.inner() { let weak = inner.weak.load(Acquire); - let strong = inner.strong.load(Acquire); + let strong = inner.strong.load(Relaxed); if strong == 0 { 0 } else { |
