Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Weaken needlessly restrictive orderings on Arc::*_count #115546

Merged
merged 1 commit into from
Sep 30, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions library/alloc/src/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1616,7 +1616,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 }
Expand Down Expand Up @@ -1646,7 +1646,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
Expand Down Expand Up @@ -2801,7 +2801,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
Expand All @@ -2820,7 +2820,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 {
Expand Down
Loading