Skip to content
Draft
Changes from 1 commit
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
15 changes: 15 additions & 0 deletions src/pool/arc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,21 @@ where
&mut *ptr::addr_of_mut!((*this.node_ptr.as_ptr().cast::<ArcInner<P::Data>>()).data)
}

/// Returns the number of strong (`Arc`) pointers to this allocation
pub fn strong_count(this: &Self) -> usize {
this.inner().strong.load(Ordering::SeqCst)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why SeqCst and not Relaxed ? This is a public API that has no use besides hinting.

}

/// 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::strong_count(this) == 1 {
// 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