From: Alice Ryhl <aliceryhl@google.com>
To: "Boqun Feng" <boqun@kernel.org>, "Gary Guo" <gary@garyguo.net>,
"Lyude Paul" <lyude@redhat.com>,
"Daniel Almeida" <daniel.almeida@collabora.com>,
"Onur Özkan" <work@onurozkan.dev>,
"Miguel Ojeda" <ojeda@kernel.org>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
"Benno Lossin" <lossin@kernel.org>,
"Andreas Hindborg" <a.hindborg@kernel.org>,
"Trevor Gross" <tmgross@umich.edu>,
"Danilo Krummrich" <dakr@kernel.org>,
"Tamir Duberstein" <tamird@kernel.org>,
"Alexandre Courbot" <acourbot@nvidia.com>
Cc: linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org,
Sid Nayyar <sidnayyar@google.com>,
Alice Ryhl <aliceryhl@google.com>
Subject: [PATCH] rust: sync: condvar: show interruptible wait in CondVar doc example
Date: Fri, 27 Nov 2026 11:29:25 +0000 [thread overview]
Message-ID: <20261127-condvar-doc-interruptible-v1-1-d61a13fb0c36@google.com> (raw)
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@google.com>
Signed-off-by: Alice Ryhl <aliceryhl@google.com>
---
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@google.com>
reply other threads:[~2026-11-27 11:29 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261127-condvar-doc-interruptible-v1-1-d61a13fb0c36@google.com \
--to=aliceryhl@google.com \
--cc=a.hindborg@kernel.org \
--cc=acourbot@nvidia.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun@kernel.org \
--cc=dakr@kernel.org \
--cc=daniel.almeida@collabora.com \
--cc=gary@garyguo.net \
--cc=linux-kernel@vger.kernel.org \
--cc=lossin@kernel.org \
--cc=lyude@redhat.com \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=sidnayyar@google.com \
--cc=tamird@kernel.org \
--cc=tmgross@umich.edu \
--cc=work@onurozkan.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®