From 5dae8f7662c3416fa9b6ad8d303ccc5a1c7cbf89 Mon Sep 17 00:00:00 2001 From: Sean Cross Date: Sun, 29 Jan 2023 18:36:38 +0800 Subject: [PATCH] kernel: don't yield when JoinThread returns immediately When waiting on a thread, it may be the case that the thread we're joining has exited already. In this case, the correct approach is to resume execution rather than switching to the parent process. This fixes an issue where `SWITCHTO_CALLER` is None when joining a short-lived thread. Signed-off-by: Sean Cross --- kernel/src/syscall.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/kernel/src/syscall.rs b/kernel/src/syscall.rs index 39263db38..1d27abba7 100644 --- a/kernel/src/syscall.rs +++ b/kernel/src/syscall.rs @@ -1145,7 +1145,11 @@ pub fn handle_inner(pid: PID, tid: TID, in_irq: bool, call: SysCall) -> SysCallR }), SysCall::JoinThread(other_tid) => { SystemServices::with_mut(|ss| ss.join_thread(pid, tid, other_tid)).map(|ret| { - unsafe { SWITCHTO_CALLER = None }; + // Successfully joining a thread causes this thread to sleep while the parent process + // is resumed. This is the same as a `Yield` + if ret == xous_kernel::Result::ResumeProcess { + unsafe { SWITCHTO_CALLER = None }; + } ret }) }