Skip to content

Commit 7e93032

Browse files
committed
weaken needlessly restrictive orderings on Arc::*_count
1 parent 4b043fa commit 7e93032

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

library/alloc/src/sync.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use core::ptr::{self, NonNull};
2525
#[cfg(not(no_global_oom_handling))]
2626
use core::slice::from_raw_parts_mut;
2727
use core::sync::atomic;
28-
use core::sync::atomic::Ordering::{Acquire, Relaxed, Release, SeqCst};
28+
use core::sync::atomic::Ordering::{Acquire, Relaxed, Release};
2929

3030
#[cfg(not(no_global_oom_handling))]
3131
use crate::alloc::handle_alloc_error;
@@ -970,7 +970,7 @@ impl<T: ?Sized> Arc<T> {
970970
#[must_use]
971971
#[stable(feature = "arc_counts", since = "1.15.0")]
972972
pub fn weak_count(this: &Self) -> usize {
973-
let cnt = this.inner().weak.load(SeqCst);
973+
let cnt = this.inner().weak.load(Acquire);
974974
// If the weak count is currently locked, the value of the
975975
// count was 0 just before taking the lock.
976976
if cnt == usize::MAX { 0 } else { cnt - 1 }
@@ -1000,7 +1000,7 @@ impl<T: ?Sized> Arc<T> {
10001000
#[must_use]
10011001
#[stable(feature = "arc_counts", since = "1.15.0")]
10021002
pub fn strong_count(this: &Self) -> usize {
1003-
this.inner().strong.load(SeqCst)
1003+
this.inner().strong.load(Acquire)
10041004
}
10051005

10061006
/// Increments the strong reference count on the `Arc<T>` associated with the
@@ -1961,7 +1961,7 @@ impl<T: ?Sized> Weak<T> {
19611961
#[must_use]
19621962
#[stable(feature = "weak_counts", since = "1.41.0")]
19631963
pub fn strong_count(&self) -> usize {
1964-
if let Some(inner) = self.inner() { inner.strong.load(SeqCst) } else { 0 }
1964+
if let Some(inner) = self.inner() { inner.strong.load(Acquire) } else { 0 }
19651965
}
19661966

19671967
/// Gets an approximation of the number of `Weak` pointers pointing to this
@@ -1980,8 +1980,8 @@ impl<T: ?Sized> Weak<T> {
19801980
pub fn weak_count(&self) -> usize {
19811981
self.inner()
19821982
.map(|inner| {
1983-
let weak = inner.weak.load(SeqCst);
1984-
let strong = inner.strong.load(SeqCst);
1983+
let weak = inner.weak.load(Acquire);
1984+
let strong = inner.strong.load(Acquire);
19851985
if strong == 0 {
19861986
0
19871987
} else {

0 commit comments

Comments
 (0)