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

Mark OnceState::poison as pub #133240

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
22 changes: 19 additions & 3 deletions library/std/src/sync/poison/once.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,13 +169,15 @@ impl Once {
/// [`call_once_force()`] will be no-ops.
///
/// The closure `f` is yielded a [`OnceState`] structure which can be used
/// to query the poison status of the [`Once`].
/// to query the poison status of the [`Once`] or mark the [`Once`] as poisoned.
///
/// [`call_once()`]: Once::call_once
/// [`call_once_force()`]: Once::call_once_force
///
/// # Examples
///
/// Poison a [`Once`] by panicking in a `call_once` closure:
///
/// ```
/// use std::sync::Once;
/// use std::thread;
Expand All @@ -202,6 +204,20 @@ impl Once {
/// // once any success happens, we stop propagating the poison
/// INIT.call_once(|| {});
/// ```
///
/// Poison a [`Once`] by explicitly calling [`OnceState::poison`]:
///
/// ```
/// #![feature(once_state_poison_pub)]
///
/// use std::sync::Once;
///
/// static INIT: Once = Once::new();
///
/// // poison the once without panicking
/// INIT.call_once_force(|p| p.poison());
/// INIT.call_once_force(|p| assert!(p.is_poisoned()));
/// ```
#[inline]
#[stable(feature = "once_poison", since = "1.51.0")]
pub fn call_once_force<F>(&self, f: F)
Expand Down Expand Up @@ -375,9 +391,9 @@ impl OnceState {
}

/// Poison the associated [`Once`] without explicitly panicking.
// NOTE: This is currently only exposed for `OnceLock`.
#[unstable(feature = "once_state_poison_pub", issue = "130327")]
#[inline]
pub(crate) fn poison(&self) {
pub fn poison(&self) {
self.inner.poison();
}
}
Expand Down
Loading