Skip to main content

qubit_lock/monitor/
wait_timeout_status.rs

1/*******************************************************************************
2 *
3 *    Copyright (c) 2025 - 2026 Haixing Hu.
4 *
5 *    SPDX-License-Identifier: Apache-2.0
6 *
7 *    Licensed under the Apache License, Version 2.0.
8 *
9 ******************************************************************************/
10//! # Wait Timeout Status
11//!
12//! Provides the status returned by one timed condition-variable wait.
13//!
14
15/// Result of a timed wait operation.
16///
17/// This status is returned by
18/// [`MonitorGuard::wait_timeout`](super::MonitorGuard::wait_timeout) and
19/// [`Monitor::wait_notify`](super::Monitor::wait_notify). It describes why a
20/// timed wait returned, but callers must still re-check the protected state
21/// because condition variables may wake spuriously.
22///
23/// # Example
24///
25/// ```rust
26/// use std::time::Duration;
27///
28/// use qubit_lock::lock::{Monitor, WaitTimeoutStatus};
29///
30/// let monitor = Monitor::new(false);
31/// let guard = monitor.lock();
32/// let (_guard, status) = guard.wait_timeout(Duration::from_millis(1));
33/// assert_eq!(status, WaitTimeoutStatus::TimedOut);
34/// ```
35#[derive(Debug, Clone, Copy, PartialEq, Eq)]
36pub enum WaitTimeoutStatus {
37    /// The wait returned before the timeout elapsed.
38    ///
39    /// This usually means another thread called
40    /// [`Monitor::notify_one`](super::Monitor::notify_one) or
41    /// [`Monitor::notify_all`](super::Monitor::notify_all), but it may also be
42    /// a spurious wakeup. Always re-check the guarded state before acting on
43    /// this status.
44    Woken,
45    /// The wait reached the timeout boundary.
46    ///
47    /// Even after this status, callers should inspect the protected state
48    /// because another thread may have changed it while the waiting thread was
49    /// reacquiring the mutex.
50    TimedOut,
51}