From b18e7d7e99b0e4f4c8064f1e8571fc6ed65c1582 Mon Sep 17 00:00:00 2001 From: Sean Cross Date: Sun, 29 Jan 2023 18:35:34 +0800 Subject: [PATCH] kernel: immediately switch to new thread on CreateThread When a new thread is created, immediately switch to the new thread. Signed-off-by: Sean Cross --- kernel/src/syscall.rs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/kernel/src/syscall.rs b/kernel/src/syscall.rs index c8c3b11d5..39263db38 100644 --- a/kernel/src/syscall.rs +++ b/kernel/src/syscall.rs @@ -1048,11 +1048,16 @@ pub fn handle_inner(pid: PID, tid: TID, in_irq: bool, call: SysCall) -> SysCallR }), SysCall::CreateThread(thread_init) => SystemServices::with_mut(|ss| { ss.create_thread(pid, thread_init).map(|new_tid| { - if !cfg!(baremetal) { - ss.switch_to_thread(pid, Some(new_tid)) - .expect("couldn't activate new thread"); - } - xous_kernel::Result::ThreadID(new_tid) + // Immediately switch to the new thread + ss.switch_to_thread(pid, Some(new_tid)) + .expect("couldn't activate new thread"); + + // Set the return value of the existing thread to be the new thread ID + ss.set_thread_result(pid, tid, xous_kernel::Result::ThreadID(new_tid)) + .expect("couldn't set new thread ID"); + + // Return `ResumeProcess` since we're switching threads + xous_kernel::Result::ResumeProcess }) }), SysCall::CreateProcess(process_init) => SystemServices::with_mut(|ss| {