summaryrefslogtreecommitdiffstats
path: root/library/std/src/sync/once.rs
diff options
context:
space:
mode:
Diffstat (limited to 'library/std/src/sync/once.rs')
-rw-r--r--library/std/src/sync/once.rs16
1 files changed, 16 insertions, 0 deletions
diff --git a/library/std/src/sync/once.rs b/library/std/src/sync/once.rs
index 0f25417d6..1b17c3108 100644
--- a/library/std/src/sync/once.rs
+++ b/library/std/src/sync/once.rs
@@ -43,6 +43,12 @@ pub struct OnceState {
pub(crate) inner: sys::OnceState,
}
+pub(crate) enum ExclusiveState {
+ Incomplete,
+ Poisoned,
+ Complete,
+}
+
/// Initialization value for static [`Once`] values.
///
/// # Examples
@@ -248,6 +254,16 @@ impl Once {
pub fn is_completed(&self) -> bool {
self.inner.is_completed()
}
+
+ /// Returns the current state of the `Once` instance.
+ ///
+ /// Since this takes a mutable reference, no initialization can currently
+ /// be running, so the state must be either "incomplete", "poisoned" or
+ /// "complete".
+ #[inline]
+ pub(crate) fn state(&mut self) -> ExclusiveState {
+ self.inner.state()
+ }
}
#[stable(feature = "std_debug", since = "1.16.0")]