lkml.org 
[lkml]   [2026]   [May]   [5]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Date
Subject[PATCH RFC 5/6] rust: impl interruptible waits for Completion
Allow Completion to wait interruptibly.

Signed-off-by: Manos Pitsidianakis <manos@pitsidianak.is>
---
rust/kernel/sync/completion.rs | 39 +++++++++++++++++++++++++++++++++++++++
1 file changed, 39 insertions(+)

diff --git a/rust/kernel/sync/completion.rs b/rust/kernel/sync/completion.rs
index c50012a940a3c7a3e0edf302c8f833bdc4415200..958e26f00a8e645ab080cb5d8529e31ac3042dd0 100644
--- a/rust/kernel/sync/completion.rs
+++ b/rust/kernel/sync/completion.rs
@@ -109,4 +109,43 @@ pub fn wait_for_completion(&self) {
// SAFETY: `self.as_raw()` is a pointer to a valid `struct completion`.
unsafe { bindings::wait_for_completion(self.as_raw()) };
}
+
+ /// Wait for completion of a task.
+ ///
+ /// This method waits for the completion of a task; it is not interruptible and there is no
+ /// timeout.
+ ///
+ /// See also [`Completion::complete_all`].
+ pub fn wait_for_completion_interruptible(&self) -> Result {
+ // SAFETY: `self.as_raw()` is a pointer to a valid `struct completion`.
+ let err = unsafe { bindings::wait_for_completion_interruptible(self.as_raw()) };
+ if err < 0 {
+ Err(Error::from_errno(err))
+ } else {
+ Ok(())
+ }
+ }
+
+ /// Wait for completion of a task.
+ ///
+ /// This method waits for the completion of a task; it is not interruptible and there is no
+ /// timeout.
+ ///
+ /// See also [`Completion::complete_all`].
+ pub fn wait_for_completion_interruptible_timeout(
+ &self,
+ timeout_jiffies: c_ulong,
+ ) -> Result<c_long> {
+ // SAFETY: `self.as_raw()` is a pointer to a valid `struct completion`.
+ let ret: c_long = unsafe {
+ bindings::wait_for_completion_interruptible_timeout(self.as_raw(), timeout_jiffies)
+ };
+ if ret == 0 {
+ Err(ETIMEDOUT)
+ } else if ret < 0 {
+ Err(Error::from_errno(ret as c_int))
+ } else {
+ Ok(ret)
+ }
+ }
}
--
2.47.3


\
 
 \ /
  Last update: 2026-05-05 10:16    [W:0.093 / U:69.002 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and my Meterkast|Read the blog