Skip to content

Commit 4c2f1c6

Browse files
committed
Weaken needlessly restrictive orderings on Arc::*_count
Signed-off-by: Alex Saveau <saveau.alexandre@gmail.com>
1 parent ec08a03 commit 4c2f1c6

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

library/alloc/src/sync.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1616,7 +1616,7 @@ impl<T: ?Sized, A: Allocator> Arc<T, A> {
16161616
#[must_use]
16171617
#[stable(feature = "arc_counts", since = "1.15.0")]
16181618
pub fn weak_count(this: &Self) -> usize {
1619-
let cnt = this.inner().weak.load(Acquire);
1619+
let cnt = this.inner().weak.load(Relaxed);
16201620
// If the weak count is currently locked, the value of the
16211621
// count was 0 just before taking the lock.
16221622
if cnt == usize::MAX { 0 } else { cnt - 1 }
@@ -1646,7 +1646,7 @@ impl<T: ?Sized, A: Allocator> Arc<T, A> {
16461646
#[must_use]
16471647
#[stable(feature = "arc_counts", since = "1.15.0")]
16481648
pub fn strong_count(this: &Self) -> usize {
1649-
this.inner().strong.load(Acquire)
1649+
this.inner().strong.load(Relaxed)
16501650
}
16511651

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

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

0 commit comments

Comments
 (0)