]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
rust: sync: expose `signal_pending` and `cond_resched` to drivers
authorWedson Almeida Filho <wedsonaf@google.com>
Fri, 23 Apr 2021 11:55:38 +0000 (12:55 +0100)
committerMiguel Ojeda <ojeda@kernel.org>
Tue, 27 Apr 2021 03:06:13 +0000 (05:06 +0200)
Signed-off-by: Wedson Almeida Filho <wedsonaf@google.com>
[normalized title]
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
rust/helpers.c
rust/kernel/sync/condvar.rs
rust/kernel/sync/mod.rs

index 133fe9119990f8850b892c2e2c21fc52dca86bcb..aa1de0eb0cbe3d0730e4eaa3a59dc5c6a238f5b1 100644 (file)
@@ -81,6 +81,12 @@ void rust_helper_kunmap(struct page *page)
 }
 EXPORT_SYMBOL_GPL(rust_helper_kunmap);
 
+int rust_helper_cond_resched(void)
+{
+       return cond_resched();
+}
+EXPORT_SYMBOL_GPL(rust_helper_cond_resched);
+
 #if !defined(CONFIG_ARM)
 // See https://github.com/rust-lang/rust-bindgen/issues/1671
 static_assert(__builtin_types_compatible_p(size_t, uintptr_t),
index 6d57fb1daea4ed66685ca9d52431ab3d8a3e2dc7..be6012794777c5eba98cd4cc5860b165a9f0200f 100644 (file)
@@ -6,12 +6,11 @@
 //! variable.
 
 use super::{Guard, Lock, NeedsLockClass};
-use crate::{bindings, c_types, CStr};
+use crate::{bindings, CStr};
 use core::{cell::UnsafeCell, marker::PhantomPinned, mem::MaybeUninit, pin::Pin};
 
 extern "C" {
     fn rust_helper_init_wait(wq: *mut bindings::wait_queue_entry);
-    fn rust_helper_signal_pending() -> c_types::c_int;
 }
 
 /// Safely initialises a [`CondVar`] with the given name, generating a new lock class.
@@ -92,8 +91,7 @@ impl CondVar {
         // SAFETY: Both `wait` and `wait_list` point to valid memory.
         unsafe { bindings::finish_wait(self.wait_list.get(), wait.as_mut_ptr()) };
 
-        // SAFETY: No arguments, just checks `current` for pending signals.
-        unsafe { rust_helper_signal_pending() != 0 }
+        super::signal_pending()
     }
 
     /// Calls the kernel function to notify the appropriate number of threads with the given flags.
index 25f5109429a8e74e264b2daa26d199f5e90e3936..0a8cec021e5c54b5a7d9272ef81e00133ca472fa 100644 (file)
@@ -17,7 +17,7 @@
 //! }
 //! ```
 
-use crate::{bindings, CStr};
+use crate::{bindings, c_types, CStr};
 use core::pin::Pin;
 
 mod arc;
@@ -34,6 +34,11 @@ pub use locked_by::LockedBy;
 pub use mutex::Mutex;
 pub use spinlock::SpinLock;
 
+extern "C" {
+    fn rust_helper_signal_pending() -> c_types::c_int;
+    fn rust_helper_cond_resched() -> c_types::c_int;
+}
+
 /// Safely initialises an object that has an `init` function that takes a name and a lock class as
 /// arguments, examples of these are [`Mutex`] and [`SpinLock`]. Each of them also provides a more
 /// specialised name that uses this macro.
@@ -66,3 +71,15 @@ pub trait NeedsLockClass {
     /// `key` must point to a valid memory location as it will be used by the kernel.
     unsafe fn init(self: Pin<&Self>, name: CStr<'static>, key: *mut bindings::lock_class_key);
 }
+
+/// Determines if a signal is pending on the current process.
+pub fn signal_pending() -> bool {
+    // SAFETY: No arguments, just checks `current` for pending signals.
+    unsafe { rust_helper_signal_pending() != 0 }
+}
+
+/// Reschedules the caller's task if needed.
+pub fn cond_resched() -> bool {
+    // SAFETY: No arguments, reschedules `current` if needed.
+    unsafe { rust_helper_cond_resched() != 0 }
+}