[PATCH] rust: sync: condvar: show interruptible wait in CondVar doc example

From: Alice Ryhl

Date: Fri Nov 27 2026 - 06:29:39 EST


The top-level `CondVar` documentation example currently only shows an
uninterruptible `wait()`, even though interruptible waits are usually
preferred so waiting tasks can respond to signals. Add an interruptible
wait function alongside the uninterruptible one in the example.

This came up while I was teaching the Rust for Linux course.

Suggested-by: Sid Nayyar <sidnayyar@xxxxxxxxxx>
Signed-off-by: Alice Ryhl <aliceryhl@xxxxxxxxxx>
---
rust/kernel/sync/condvar.rs | 18 ++++++++++++++++--
1 file changed, 16 insertions(+), 2 deletions(-)

diff --git a/rust/kernel/sync/condvar.rs b/rust/kernel/sync/condvar.rs
index 69d58dfbad7b..fba82650842c 100644
--- a/rust/kernel/sync/condvar.rs
+++ b/rust/kernel/sync/condvar.rs
@@ -54,8 +54,22 @@ macro_rules! new_condvar {
/// value_changed: CondVar,
/// }
///
-/// /// Waits for `e.value` to become `v`.
-/// fn wait_for_value(e: &Example, v: u32) {
+/// /// Waits for `e.value` to become `v`, returning `Err(ERESTARTSYS)` if a signal is received.
+/// ///
+/// /// Prefer interruptible waits when the caller can handle interruption, so waiting tasks remain
+/// /// killable.
+/// fn wait_for_value(e: &Example, v: u32) -> Result {
+/// let mut guard = e.value.lock();
+/// while *guard != v {
+/// if e.value_changed.wait_interruptible(&mut guard) {
+/// return Err(ERESTARTSYS);
+/// }
+/// }
+/// Ok(())
+/// }
+///
+/// /// Waits uninterruptibly for `e.value` to become `v`.
+/// fn wait_for_value_uninterruptible(e: &Example, v: u32) {
/// let mut guard = e.value.lock();
/// while *guard != v {
/// e.value_changed.wait(&mut guard);

---
base-commit: b6a9fa34ce4187cb69d3c588a4bbffc31ce5db8f
change-id: 20261126-condvar-doc-interruptible-72bb4754c9bd

Best regards,
--
Alice Ryhl <aliceryhl@xxxxxxxxxx>