Skip to content

Commit 0a7f5ba

Browse files
fbqojeda
authored andcommitted
rust: sync: Makes CondVar::wait() an uninterruptible wait
Currently, `CondVar::wait()` is an interruptible wait, and this is different than `wait_event()` in include/linux/wait.h (which is an uninterruptible wait). To avoid confusion between different APIs on the interruptible/uninterruptible, make `CondVar::wait()` an uninterruptible wait same as `wait_event()`, also rename the old `wait()` to `CondVar::wait_interruptible()`. Spotted-by: Tiago Lam <[email protected]> Signed-off-by: Boqun Feng <[email protected]> Reviewed-by: Benno Lossin <[email protected]> Reviewed-by: Alice Ryhl <[email protected]> Reviewed-by: Tiago Lam <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Miguel Ojeda <[email protected]>
1 parent 80fe9e5 commit 0a7f5ba

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

rust/kernel/sync/condvar.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ macro_rules! new_condvar {
5050
/// fn wait_for_value(e: &Example, v: u32) {
5151
/// let mut guard = e.value.lock();
5252
/// while *guard != v {
53-
/// e.value_changed.wait_uninterruptible(&mut guard);
53+
/// e.value_changed.wait(&mut guard);
5454
/// }
5555
/// }
5656
///
@@ -120,28 +120,28 @@ impl CondVar {
120120
unsafe { bindings::finish_wait(self.wait_list.get(), wait.get()) };
121121
}
122122

123-
/// Releases the lock and waits for a notification in interruptible mode.
123+
/// Releases the lock and waits for a notification in uninterruptible mode.
124124
///
125125
/// Atomically releases the given lock (whose ownership is proven by the guard) and puts the
126126
/// thread to sleep, reacquiring the lock on wake up. It wakes up when notified by
127-
/// [`CondVar::notify_one`] or [`CondVar::notify_all`], or when the thread receives a signal.
128-
/// It may also wake up spuriously.
127+
/// [`CondVar::notify_one`] or [`CondVar::notify_all`]. Note that it may also wake up
128+
/// spuriously.
129+
pub fn wait<T: ?Sized, B: Backend>(&self, guard: &mut Guard<'_, T, B>) {
130+
self.wait_internal(bindings::TASK_UNINTERRUPTIBLE, guard);
131+
}
132+
133+
/// Releases the lock and waits for a notification in interruptible mode.
134+
///
135+
/// Similar to [`CondVar::wait`], except that the wait is interruptible. That is, the thread may
136+
/// wake up due to signals. It may also wake up spuriously.
129137
///
130138
/// Returns whether there is a signal pending.
131-
#[must_use = "wait returns if a signal is pending, so the caller must check the return value"]
132-
pub fn wait<T: ?Sized, B: Backend>(&self, guard: &mut Guard<'_, T, B>) -> bool {
139+
#[must_use = "wait_interruptible returns if a signal is pending, so the caller must check the return value"]
140+
pub fn wait_interruptible<T: ?Sized, B: Backend>(&self, guard: &mut Guard<'_, T, B>) -> bool {
133141
self.wait_internal(bindings::TASK_INTERRUPTIBLE, guard);
134142
crate::current!().signal_pending()
135143
}
136144

137-
/// Releases the lock and waits for a notification in uninterruptible mode.
138-
///
139-
/// Similar to [`CondVar::wait`], except that the wait is not interruptible. That is, the
140-
/// thread won't wake up due to signals. It may, however, wake up supirously.
141-
pub fn wait_uninterruptible<T: ?Sized, B: Backend>(&self, guard: &mut Guard<'_, T, B>) {
142-
self.wait_internal(bindings::TASK_UNINTERRUPTIBLE, guard)
143-
}
144-
145145
/// Calls the kernel function to notify the appropriate number of threads with the given flags.
146146
fn notify(&self, count: i32, flags: u32) {
147147
// SAFETY: `wait_list` points to valid memory.

0 commit comments

Comments
 (0)