Skip to content

Commit

Permalink
Add strong/weak pointer counts to Shared (rust-lang#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 committed Feb 14, 2021
1 parent 5e0e00c commit e74dcf4
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions futures-util/src/future/future/shared.rs
Expand Up @@ -123,6 +123,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 e74dcf4

Please sign in to comment.