FROMGIT: rust: sync: condvar: Add wait_interruptible_freezable()
To support waiting for a `CondVar` as a freezable process, add a wait_interruptible_freezable() function. Binder needs this function in the appropriate places to freeze a process where some of its threads are blocked on the Binder driver. [Boqun: Capitalize the title and reword the commit log] Signed-off-by: Alice Ryhl <aliceryhl@google.com> Signed-off-by: Boqun Feng <boqun.feng@gmail.com> Link: https://lore.kernel.org/r/20250204-condvar-freeze-v2-1-804483096260@google.com Bug: 388786466 (cherry picked from commit 39dfd06783c0e256f420695ea85d95a5f471bc22 git://git.kernel.org/pub/scm/linux/kernel/git/boqun/linux.git lockdep-for-tip) Change-Id: I04c41d20868898a3371ebafa54e4afb76edc762e Signed-off-by: Alice Ryhl <aliceryhl@google.com>
This commit is contained in:
@@ -10,7 +10,9 @@ use crate::{
|
||||
init::PinInit,
|
||||
pin_init,
|
||||
str::CStr,
|
||||
task::{MAX_SCHEDULE_TIMEOUT, TASK_INTERRUPTIBLE, TASK_NORMAL, TASK_UNINTERRUPTIBLE},
|
||||
task::{
|
||||
MAX_SCHEDULE_TIMEOUT, TASK_FREEZABLE, TASK_INTERRUPTIBLE, TASK_NORMAL, TASK_UNINTERRUPTIBLE,
|
||||
},
|
||||
time::Jiffies,
|
||||
types::Opaque,
|
||||
};
|
||||
@@ -160,6 +162,25 @@ impl CondVar {
|
||||
crate::current!().signal_pending()
|
||||
}
|
||||
|
||||
/// Releases the lock and waits for a notification in interruptible and freezable mode.
|
||||
///
|
||||
/// The process is allowed to be frozen during this sleep. You must not hold any locks while
|
||||
/// this operation is ongoing, and there is a lockdep assertion for this. Freezing a task that
|
||||
/// holds a lock can trivially deadlock vs another task that needs that lock to complete before
|
||||
/// it too can hit freezable.
|
||||
#[must_use = "wait returns if a signal is pending, so the caller must check the return value"]
|
||||
pub fn wait_interruptible_freezable<T: ?Sized, B: Backend>(
|
||||
&self,
|
||||
guard: &mut Guard<'_, T, B>,
|
||||
) -> bool {
|
||||
self.wait_internal(
|
||||
TASK_INTERRUPTIBLE | TASK_FREEZABLE,
|
||||
guard,
|
||||
MAX_SCHEDULE_TIMEOUT,
|
||||
);
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user