Skip to content

Commit 4efd655

Browse files
committed
Auto merge of #115546 - SUPERCILEX:patch-2, r=Amanieu
Weaken needlessly restrictive orderings on Arc::*_count Follow up to #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.
2 parents b8b376a + 4c2f1c6 commit 4efd655

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

Diff for: library/alloc/src/sync.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1618,7 +1618,7 @@ impl<T: ?Sized, A: Allocator> Arc<T, A> {
16181618
#[must_use]
16191619
#[stable(feature = "arc_counts", since = "1.15.0")]
16201620
pub fn weak_count(this: &Self) -> usize {
1621-
let cnt = this.inner().weak.load(Acquire);
1621+
let cnt = this.inner().weak.load(Relaxed);
16221622
// If the weak count is currently locked, the value of the
16231623
// count was 0 just before taking the lock.
16241624
if cnt == usize::MAX { 0 } else { cnt - 1 }
@@ -1648,7 +1648,7 @@ impl<T: ?Sized, A: Allocator> Arc<T, A> {
16481648
#[must_use]
16491649
#[stable(feature = "arc_counts", since = "1.15.0")]
16501650
pub fn strong_count(this: &Self) -> usize {
1651-
this.inner().strong.load(Acquire)
1651+
this.inner().strong.load(Relaxed)
16521652
}
16531653

16541654
/// Increments the strong reference count on the `Arc<T>` associated with the
@@ -2803,7 +2803,7 @@ impl<T: ?Sized, A: Allocator> Weak<T, A> {
28032803
#[must_use]
28042804
#[stable(feature = "weak_counts", since = "1.41.0")]
28052805
pub fn strong_count(&self) -> usize {
2806-
if let Some(inner) = self.inner() { inner.strong.load(Acquire) } else { 0 }
2806+
if let Some(inner) = self.inner() { inner.strong.load(Relaxed) } else { 0 }
28072807
}
28082808

28092809
/// Gets an approximation of the number of `Weak` pointers pointing to this
@@ -2822,7 +2822,7 @@ impl<T: ?Sized, A: Allocator> Weak<T, A> {
28222822
pub fn weak_count(&self) -> usize {
28232823
if let Some(inner) = self.inner() {
28242824
let weak = inner.weak.load(Acquire);
2825-
let strong = inner.strong.load(Acquire);
2825+
let strong = inner.strong.load(Relaxed);
28262826
if strong == 0 {
28272827
0
28282828
} else {

0 commit comments

Comments
 (0)