}
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),
//! 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.
// 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.
//! }
//! ```
-use crate::{bindings, CStr};
+use crate::{bindings, c_types, CStr};
use core::pin::Pin;
mod arc;
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.
/// `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 }
+}