Skip to content

Commit

Permalink
zephyr-core: add safe binding for k_thread_suspend
Browse files Browse the repository at this point in the history
Needed for direct implementation of thread_parking in std
  • Loading branch information
tylerwhall committed Oct 9, 2024
1 parent e88bb95 commit acd7a3e
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions rust/zephyr-core/src/thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ impl ThreadId {
self.0.as_ptr()
}

pub fn k_thread_suspend<C: ThreadSyscalls>(&self) {
C::k_thread_suspend(*self)
}

pub fn k_wakeup<C: ThreadSyscalls>(&self) {
C::k_wakeup(*self)
}
Expand All @@ -20,6 +24,7 @@ impl ThreadId {
}

pub trait ThreadSyscalls {
fn k_thread_suspend(thread: ThreadId);
fn k_wakeup(thread: ThreadId);
fn k_current_get() -> crate::thread::ThreadId;
fn k_object_access_grant<K: KObj>(kobj: &K, thread: ThreadId);
Expand All @@ -28,6 +33,10 @@ pub trait ThreadSyscalls {
macro_rules! trait_impl {
($context:ident, $context_struct:path) => {
impl ThreadSyscalls for $context_struct {
fn k_thread_suspend(thread: ThreadId) {
unsafe { zephyr_sys::syscalls::$context::k_thread_suspend(thread.tid()) }
}

fn k_wakeup(thread: ThreadId) {
unsafe { zephyr_sys::syscalls::$context::k_wakeup(thread.tid()) }
}
Expand Down

0 comments on commit acd7a3e

Please sign in to comment.