Skip to content

Commit

Permalink
Mark OnceState::poison as pub
Browse files Browse the repository at this point in the history
  • Loading branch information
caass authored and GrigorenkoPV committed Jan 3, 2025
1 parent ac00fe8 commit 4f6e873
Showing 1 changed file with 19 additions and 3 deletions.
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

0 comments on commit 4f6e873

Please sign in to comment.