Skip to content

Commit

Permalink
[fix] cargo doc error in condvar
Browse files Browse the repository at this point in the history
  • Loading branch information
hky1999 committed Oct 28, 2024
1 parent 82172c1 commit d92b26e
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 7 deletions.
2 changes: 0 additions & 2 deletions modules/axsync/src/condvar/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,9 @@ pub use multitask::Condvar;
/// It is returned by the [`wait_timeout`] method.
///
/// [`wait_timeout`]: Condvar::wait_timeout
#[cfg(feature = "irq")]
#[derive(Debug, PartialEq, Eq, Copy, Clone)]
pub struct WaitTimeoutResult(bool);

#[cfg(feature = "irq")]
impl WaitTimeoutResult {
/// Returns `true` if the wait was known to have timed out.
#[must_use]
Expand Down
38 changes: 33 additions & 5 deletions modules/axsync/src/condvar/multitask.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
use core::fmt;
use core::sync::atomic::AtomicU32;
use core::sync::atomic::Ordering::Relaxed;

#[cfg(feature = "irq")]
use core::time::Duration;

use axtask::WaitQueue;

use crate::{mutex, MutexGuard};

#[cfg(feature = "irq")]
use crate::condvar::WaitTimeoutResult;
use crate::{mutex, MutexGuard};

/// A Condition Variable
///
Expand Down Expand Up @@ -56,6 +52,9 @@ impl Condvar {
/// variables normally have a boolean predicate associated with them, and
/// the predicate must always be checked each time this function returns to
/// protect against spurious wakeups.
///
/// [`notify_one`]: Self::notify_one
/// [`notify_all`]: Self::notify_all
pub fn wait<'a, T>(&self, guard: MutexGuard<'a, T>) -> MutexGuard<'a, T> {
// Examine the notification counter _before_ we unlock the mutex.
let expected_counter = self.notify_counter.load(Relaxed);
Expand Down Expand Up @@ -86,6 +85,10 @@ impl Condvar {
/// to [`notify_one`] or [`notify_all`] which happen logically after the
/// mutex is unlocked are candidates to wake this thread up. When this
/// function call returns, the lock specified will have been re-acquired.
///
/// [`wait`]: Self::wait
/// [`notify_one`]: Self::notify_one
/// [`notify_all`]: Self::notify_all
pub fn wait_while<'a, T, F>(
&self,
mut guard: MutexGuard<'a, T>,
Expand Down Expand Up @@ -125,6 +128,9 @@ impl Condvar {
///
/// Like [`wait`], the lock specified will be re-acquired when this function
/// returns, regardless of whether the timeout elapsed or not.
///
/// [`wait`]: Self::wait
/// [`WaitTimeoutResult`]: crate::WaitTimeoutResult
#[cfg(feature = "irq")]
pub fn wait_timeout<'a, T>(
&self,
Expand All @@ -150,6 +156,15 @@ impl Condvar {
(mutex.lock(), WaitTimeoutResult(!success))
}

#[cfg(not(feature = "irq"))]
pub fn wait_timeout<'a, T>(
&self,
_guard: MutexGuard<'a, T>,
_dur: Duration,
) -> (MutexGuard<'a, T>, WaitTimeoutResult) {
unimplemented!("wait_timeout should be used with the `irq` feature enabled")
}

/// Waits on this condition variable for a notification, timing out after a
/// specified duration.
///
Expand Down Expand Up @@ -195,6 +210,19 @@ impl Condvar {
}
}

#[cfg(not(feature = "irq"))]
pub fn wait_timeout_while<'a, T, F>(
&self,
mut _guard: MutexGuard<'a, T>,
_dur: Duration,
mut _condition: F,
) -> (MutexGuard<'a, T>, WaitTimeoutResult)
where
F: FnMut(&mut T) -> bool,
{
unimplemented!("wait_timeout_while should be used with the `irq` feature enabled")
}

/// Wakes up one blocked thread on this condvar.
///
/// If there is a blocked thread on this condition variable, then it will
Expand Down

0 comments on commit d92b26e

Please sign in to comment.