From: Boqun Feng <boqun.feng@gmail.com>
To: rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: "Tiago Lam" <tiagolam@gmail.com>,
"Miguel Ojeda" <ojeda@kernel.org>,
"Alex Gaynor" <alex.gaynor@gmail.com>,
"Wedson Almeida Filho" <wedsonaf@gmail.com>,
"Gary Guo" <gary@garyguo.net>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
"Alice Ryhl" <aliceryhl@google.com>,
"Benno Lossin" <benno.lossin@proton.me>,
"Andreas Hindborg" <a.hindborg@samsung.com>,
"Peter Zijlstra" <peterz@infradead.org>,
"Ingo Molnar" <mingo@redhat.com>, "Will Deacon" <will@kernel.org>,
"Waiman Long" <longman@redhat.com>,
"Martin Rodriguez Reboredo" <yakoyoku@gmail.com>,
"Boqun Feng" <boqun.feng@gmail.com>
Subject: [PATCH] rust: sync: Makes `CondVar::wait()` an uninterruptible wait
Date: Thu, 14 Dec 2023 12:04:21 -0800 [thread overview]
Message-ID: <20231214200421.690629-1-boqun.feng@gmail.com> (raw)
In-Reply-To: <ZXtebif2S1CyJRik@boqun-archlinux>
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 <tiagolam@gmail.com>
Signed-off-by: Boqun Feng <boqun.feng@gmail.com>
---
rust/kernel/sync/condvar.rs | 28 ++++++++++++++--------------
1 file changed, 14 insertions(+), 14 deletions(-)
diff --git a/rust/kernel/sync/condvar.rs b/rust/kernel/sync/condvar.rs
index b679b6f6dbeb..8630faa29b78 100644
--- a/rust/kernel/sync/condvar.rs
+++ b/rust/kernel/sync/condvar.rs
@@ -50,7 +50,7 @@ macro_rules! new_condvar {
/// fn wait_for_value(e: &Example, v: u32) {
/// let mut guard = e.value.lock();
/// while *guard != v {
-/// e.value_changed.wait_uninterruptible(&mut guard);
+/// e.value_changed.wait(&mut guard);
/// }
/// }
///
@@ -120,28 +120,28 @@ fn wait_internal<T: ?Sized, B: Backend>(&self, wait_state: u32, guard: &mut Guar
unsafe { bindings::finish_wait(self.wait_list.get(), wait.get()) };
}
- /// Releases the lock and waits for a notification in interruptible mode.
+ /// Releases the lock and waits for a notification in uninterruptible mode.
///
/// Atomically releases the given lock (whose ownership is proven by the guard) and puts the
/// thread to sleep, reacquiring the lock on wake up. It wakes up when notified by
- /// [`CondVar::notify_one`] or [`CondVar::notify_all`], or when the thread receives a signal.
- /// It may also wake up spuriously.
+ /// [`CondVar::notify_one`] or [`CondVar::notify_all`]. Note that it may also wake up
+ /// spuriously.
+ pub fn wait<T: ?Sized, B: Backend>(&self, guard: &mut Guard<'_, T, B>) {
+ self.wait_internal(bindings::TASK_UNINTERRUPTIBLE, guard);
+ }
+
+ /// Releases the lock and waits for a notification in interruptible mode.
+ ///
+ /// Similar to [`CondVar::wait`], except that the wait is interruptible. That is, the thread may
+ /// wake up due to signals. It may also wake up spuriously.
///
/// Returns whether there is a signal pending.
- #[must_use = "wait returns if a signal is pending, so the caller must check the return value"]
- pub fn wait<T: ?Sized, B: Backend>(&self, guard: &mut Guard<'_, T, B>) -> bool {
+ #[must_use = "wait_interruptible returns if a signal is pending, so the caller must check the return value"]
+ pub fn wait_interruptible<T: ?Sized, B: Backend>(&self, guard: &mut Guard<'_, T, B>) -> bool {
self.wait_internal(bindings::TASK_INTERRUPTIBLE, guard);
crate::current!().signal_pending()
}
- /// Releases the lock and waits for a notification in uninterruptible mode.
- ///
- /// Similar to [`CondVar::wait`], except that the wait is not interruptible. That is, the
- /// thread won't wake up due to signals. It may, however, wake up supirously.
- pub fn wait_uninterruptible<T: ?Sized, B: Backend>(&self, guard: &mut Guard<'_, T, B>) {
- self.wait_internal(bindings::TASK_UNINTERRUPTIBLE, guard)
- }
-
/// Calls the kernel function to notify the appropriate number of threads with the given flags.
fn notify(&self, count: i32, flags: u32) {
// SAFETY: `wait_list` points to valid memory.
--
2.43.0
next prev parent reply other threads:[~2023-12-14 20:04 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-12-06 10:09 [PATCH 0/2] Additional CondVar methods needed by Rust Binder Alice Ryhl
2023-12-06 10:09 ` [PATCH 1/2] rust: sync: add `CondVar::notify_sync` Alice Ryhl
2023-12-06 15:49 ` Martin Rodriguez Reboredo
2023-12-07 20:21 ` Benno Lossin
2023-12-08 7:29 ` Alice Ryhl
2023-12-08 9:30 ` Benno Lossin
2023-12-06 10:09 ` [PATCH 2/2] rust: sync: add `CondVar::wait_timeout` Alice Ryhl
2023-12-06 15:53 ` Martin Rodriguez Reboredo
2023-12-06 16:38 ` Alice Ryhl
2023-12-06 16:30 ` Boqun Feng
2023-12-06 16:39 ` Peter Zijlstra
2023-12-06 16:42 ` Alice Ryhl
2023-12-06 16:53 ` Peter Zijlstra
2023-12-06 17:00 ` Alice Ryhl
2023-12-06 17:05 ` Tiago Lam
2023-12-08 7:37 ` Alice Ryhl
2023-12-08 9:27 ` Benno Lossin
2023-12-12 9:45 ` Alice Ryhl
2023-12-14 19:58 ` Boqun Feng
2023-12-14 20:04 ` Boqun Feng [this message]
2023-12-15 10:27 ` [PATCH] rust: sync: Makes `CondVar::wait()` an uninterruptible wait Alice Ryhl
2023-12-15 23:45 ` Boqun Feng
2023-12-18 17:39 ` Benno Lossin
2023-12-18 20:57 ` Boqun Feng
2023-12-15 11:58 ` Tiago Lam
2023-12-20 11:11 ` Benno Lossin
2023-12-21 21:43 ` Miguel Ojeda
2023-12-08 19:04 ` [PATCH 2/2] rust: sync: add `CondVar::wait_timeout` Benno Lossin
2023-12-12 9:51 ` Alice Ryhl
2023-12-12 17:05 ` Benno Lossin
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=20231214200421.690629-1-boqun.feng@gmail.com \
--to=boqun.feng@gmail.com \
--cc=a.hindborg@samsung.com \
--cc=alex.gaynor@gmail.com \
--cc=aliceryhl@google.com \
--cc=benno.lossin@proton.me \
--cc=bjorn3_gh@protonmail.com \
--cc=gary@garyguo.net \
--cc=linux-kernel@vger.kernel.org \
--cc=longman@redhat.com \
--cc=mingo@redhat.com \
--cc=ojeda@kernel.org \
--cc=peterz@infradead.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=tiagolam@gmail.com \
--cc=wedsonaf@gmail.com \
--cc=will@kernel.org \
--cc=yakoyoku@gmail.com \
/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;
as well as URLs for NNTP newsgroup(s).