mirror of
https://github.com/torvalds/linux.git
synced 2026-05-12 16:18:45 +02:00
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: Cleaned up the changelog and documentation. ] Signed-off-by: Alice Ryhl <aliceryhl@google.com> Signed-off-by: Boqun Feng <boqun.feng@gmail.com> Signed-off-by: Ingo Molnar <mingo@kernel.org> Link: https://lore.kernel.org/r/20250307232717.1759087-10-boqun.feng@gmail.com
This commit is contained in:
parent
c2849afafd
commit
70b9c8563c
|
|
@ -11,7 +11,9 @@
|
|||
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,
|
||||
};
|
||||
|
|
@ -159,6 +161,25 @@ pub fn wait_interruptible<T: ?Sized, B: Backend>(&self, guard: &mut Guard<'_, T,
|
|||
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. No lock should be held when calling
|
||||
/// this function, 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_interruptible_freezable 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
|
||||
|
|
|
|||
|
|
@ -23,6 +23,8 @@
|
|||
pub const TASK_INTERRUPTIBLE: c_int = bindings::TASK_INTERRUPTIBLE as c_int;
|
||||
/// Bitmask for tasks that are sleeping in an uninterruptible state.
|
||||
pub const TASK_UNINTERRUPTIBLE: c_int = bindings::TASK_UNINTERRUPTIBLE as c_int;
|
||||
/// Bitmask for tasks that are sleeping in a freezable state.
|
||||
pub const TASK_FREEZABLE: c_int = bindings::TASK_FREEZABLE as c_int;
|
||||
/// Convenience constant for waking up tasks regardless of whether they are in interruptible or
|
||||
/// uninterruptible sleep.
|
||||
pub const TASK_NORMAL: c_uint = bindings::TASK_NORMAL as c_uint;
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user