Skip to content
Draft
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
18 changes: 17 additions & 1 deletion src/pool/arc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ use core::{
fmt,
hash::{Hash, Hasher},
mem::{ManuallyDrop, MaybeUninit},
ops, ptr,
ops,
ptr::{self},
};

#[cfg(not(feature = "portable-atomic"))]
Expand Down Expand Up @@ -218,6 +219,21 @@ where
&mut *ptr::addr_of_mut!((*this.node_ptr.as_ptr().cast::<ArcInner<P::Data>>()).data)
}

/// Returns `true` if there are no other `Arc` pointers to the same allocation
pub fn is_unique(this: &Self) -> bool {
this.inner().strong.load(Ordering::Acquire) == 1
}

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

#[inline(never)]
unsafe fn drop_slow(&mut self) {
// run `P::Data`'s destructor
Expand Down
Loading