Skip to content

Commit bbff5bf

Browse files
committed
correct strong count acquisition for get_mut
1 parent 600833d commit bbff5bf

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/pool/arc.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ use core::{
7373
fmt,
7474
hash::{Hash, Hasher},
7575
mem::{ManuallyDrop, MaybeUninit},
76-
ops, ptr,
76+
ops,
77+
ptr::{self, NonNull},
7778
};
7879

7980
#[cfg(not(feature = "portable-atomic"))]
@@ -218,14 +219,14 @@ where
218219
&mut *ptr::addr_of_mut!((*this.node_ptr.as_ptr().cast::<ArcInner<P::Data>>()).data)
219220
}
220221

221-
/// Returns the number of strong (`Arc`) pointers to this allocation
222-
pub fn strong_count(this: &Self) -> usize {
223-
this.inner().strong.load(Ordering::SeqCst)
222+
/// Returns `true` if there are no other `Arc` pointers to the same allocation
223+
pub fn is_unique(this: &Self) -> bool {
224+
this.inner().strong.load(Ordering::Acquire) == 1
224225
}
225226

226227
/// Returns a mutable reference to the inner data if there are no other `Arc` pointers to the
227228
pub fn get_mut(this: &mut Self) -> Option<&mut P::Data> {
228-
if Self::strong_count(this) == 1 {
229+
if Self::is_unique(this) {
229230
// SAFETY: we just checked that the strong count is 1
230231
Some(unsafe { Self::get_mut_unchecked(this) })
231232
} else {

0 commit comments

Comments
 (0)