Skip to content

Commit

Permalink
Add strong/weak pointer counts to Shared (#2346)
Browse files Browse the repository at this point in the history
Co-authored-by: Harry Barber <harry.barber@disneystreaming.com>
  • Loading branch information
hlbarber and Harry Barber authored Feb 14, 2021
1 parent 6acaa81 commit 4959ecc
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions futures-util/src/future/future/shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,32 @@ where
}
None
}

/// Gets the number of strong pointers to this allocation.
///
/// Returns [`None`] if it has already been polled to completion.
///
/// # Safety
///
/// This method by itself is safe, but using it correctly requires extra care. Another thread
/// can change the strong count at any time, including potentially between calling this method
/// and acting on the result.
pub fn strong_count(&self) -> Option<usize> {
self.inner.as_ref().map(|arc| Arc::strong_count(arc))
}

/// Gets the number of weak pointers to this allocation.
///
/// Returns [`None`] if it has already been polled to completion.
///
/// # Safety
///
/// This method by itself is safe, but using it correctly requires extra care. Another thread
/// can change the weak count at any time, including potentially between calling this method
/// and acting on the result.
pub fn weak_count(&self) -> Option<usize> {
self.inner.as_ref().map(|arc| Arc::weak_count(arc))
}
}

impl<Fut> Inner<Fut>
Expand Down

0 comments on commit 4959ecc

Please sign in to comment.