Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add strong/weak pointer counts to Shared #2346

Merged
merged 2 commits into from Feb 14, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 26 additions & 0 deletions futures-util/src/future/future/shared.rs
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