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 <sean@xobs.io>
This commit is contained in:
Sean Cross 2023-01-29 18:36:38 +08:00
parent b18e7d7e99
commit 5dae8f7662

View file

@ -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
})
}