From: Danilo Krummrich <dakr@kernel.org>
To: boqun@kernel.org, gary@garyguo.net, aliceryhl@google.com,
lyude@redhat.com, daniel.almeida@collabora.com,
work@onurozkan.dev, ojeda@kernel.org, bjorn3_gh@protonmail.com,
lossin@kernel.org, a.hindborg@kernel.org, tmgross@umich.edu,
dakr@kernel.org, tamird@kernel.org, acourbot@nvidia.com,
viro@zeniv.linux.org.uk, brauner@kernel.org, jack@suse.cz
Cc: linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org,
linux-fsdevel@vger.kernel.org
Subject: [PATCH v2 5/5] rust: sync: condvar: add non-exclusive freezable waiting
Date: Thu, 5 Nov 2026 01:59:42 +0100 [thread overview]
Message-ID: <20261105005951.756157-6-dakr@kernel.org> (raw)
In-Reply-To: <20261105005951.756157-1-dakr@kernel.org>
CondVar currently registers all sleeping tasks as exclusive waiters.
Add wait_interruptible_freezable_nonexclusive() for callers that need
non-exclusive waits, using WaitQueue::wait_once().
Document that notify_one() and notify_sync() also wake all non-exclusive
waiters.
This provides non-exclusive waiting support for a subsequent Binder
conversion.
Signed-off-by: Danilo Krummrich <dakr@kernel.org>
---
rust/kernel/sync/condvar.rs | 27 +++++++++++++++++++++++++--
rust/kernel/sync/wait.rs | 1 -
2 files changed, 25 insertions(+), 3 deletions(-)
diff --git a/rust/kernel/sync/condvar.rs b/rust/kernel/sync/condvar.rs
index fcab90f6ce34..cbc543de214f 100644
--- a/rust/kernel/sync/condvar.rs
+++ b/rust/kernel/sync/condvar.rs
@@ -148,6 +148,29 @@ pub fn wait_interruptible_freezable<T: ?Sized, B: Backend>(
crate::current!().signal_pending()
}
+ /// Releases the lock and waits non-exclusively in interruptible and freezable mode.
+ ///
+ /// Like [`CondVar::wait_interruptible_freezable`], but registers the current task as a
+ /// non-exclusive waiter.
+ ///
+ /// The lock is reacquired before returning. The wait may also end due to a signal or a
+ /// spurious wakeup.
+ ///
+ /// No lock other than the one released through `guard` should be held, since the task may
+ /// be frozen while sleeping.
+ ///
+ /// Returns whether there is a signal pending.
+ #[must_use = "the caller must check whether a signal is pending"]
+ pub fn wait_interruptible_freezable_nonexclusive<T: ?Sized, B: Backend>(
+ &self,
+ guard: &mut Guard<'_, T, B>,
+ ) -> bool {
+ self.wq.wait_once(TASK_INTERRUPTIBLE | TASK_FREEZABLE, || {
+ guard.do_unlocked(|| task::schedule_timeout(Jiffies::MAX))
+ });
+ crate::current!().signal_pending()
+ }
+
/// Releases the lock and waits for a notification in interruptible mode.
///
/// Atomically releases the given lock (whose ownership is proven by the guard) and puts the
@@ -168,7 +191,7 @@ pub fn wait_interruptible_timeout<T: ?Sized, B: Backend>(
}
}
- /// Calls the kernel function to notify one thread synchronously.
+ /// Wakes all non-exclusive waiters and one exclusive waiter synchronously.
///
/// This method behaves like `notify_one`, except that it hints to the scheduler that the
/// current thread expects to sleep soon.
@@ -177,7 +200,7 @@ pub fn notify_sync(&self) {
self.wq.wake_up_sync();
}
- /// Wakes a single waiter up, if any.
+ /// Wakes all non-exclusive waiters and one exclusive waiter, if any.
///
/// This is not 'sticky' in the sense that if no thread is waiting, the notification is lost
/// completely (as opposed to automatically waking up the next waiter).
diff --git a/rust/kernel/sync/wait.rs b/rust/kernel/sync/wait.rs
index 92c1ae93705e..942f96b5cf17 100644
--- a/rust/kernel/sync/wait.rs
+++ b/rust/kernel/sync/wait.rs
@@ -208,7 +208,6 @@ fn wait_event_timeout_internal<F: FnMut() -> bool>(
/// Performs a single non-exclusive prepare-to-wait / finish-wait cycle, calling `schedule_fn`
/// in between. Non-exclusive waiters are all woken by [`wake_up()`](Self::wake_up).
#[inline]
- #[expect(unused)]
pub(super) fn wait_once<F, R>(&self, wait_state: c_int, schedule_fn: F) -> R
where
F: FnOnce() -> R,
--
2.56.0
prev parent reply other threads:[~2026-11-05 1:00 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-05 0:59 [PATCH v2 0/5] rust: sync: add WaitQueue infrastructure Danilo Krummrich
2026-11-05 0:59 ` [PATCH v2 1/5] rust: task: add safe schedule_timeout() wrapper Danilo Krummrich
2026-11-05 4:20 ` FUJITA Tomonori
2026-11-05 0:59 ` [PATCH v2 2/5] rust: sync: add WaitQueue infrastructure Danilo Krummrich
2026-11-05 0:59 ` [PATCH v2 3/5] rust: sync: convert CondVar and PollCondVar to use WaitQueue Danilo Krummrich
2026-11-05 0:59 ` [PATCH v2 4/5] rust: sync: condvar: use task::schedule_timeout() Danilo Krummrich
2026-11-05 0:59 ` Danilo Krummrich [this message]
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=20261105005951.756157-6-dakr@kernel.org \
--to=dakr@kernel.org \
--cc=a.hindborg@kernel.org \
--cc=acourbot@nvidia.com \
--cc=aliceryhl@google.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun@kernel.org \
--cc=brauner@kernel.org \
--cc=daniel.almeida@collabora.com \
--cc=gary@garyguo.net \
--cc=jack@suse.cz \
--cc=linux-fsdevel@vger.kernel.org \
--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=tamird@kernel.org \
--cc=tmgross@umich.edu \
--cc=viro@zeniv.linux.org.uk \
--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®