From b43366e6ec0ddca66690ac0d6682e3210c1b606e Mon Sep 17 00:00:00 2001 From: Sean Cross Date: Wed, 25 Aug 2021 16:03:06 +0800 Subject: [PATCH] kernel: services: fix suspend for running processes If a process is currently running, it needs to be placed into the `Debug` state rather than the `Ready` state. Additionally, the process that's being switched to must enter the `Running` state. Signed-off-by: Sean Cross --- kernel/src/services.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/kernel/src/services.rs b/kernel/src/services.rs index d38d6e120..44bb6a2b1 100644 --- a/kernel/src/services.rs +++ b/kernel/src/services.rs @@ -2112,10 +2112,22 @@ impl SystemServices { // but without a context to switch to. p.set_tid(parent_process.previous_thread).unwrap(); parent_process.current_thread = parent_process.previous_thread; + parent_process.state = match parent_process.state { + ProcessState::Ready(x) | ProcessState::Running(x) + if x & (1 << parent_process.previous_thread) != 0 => + { + ProcessState::Running(x & !(1 << parent_process.previous_thread)) + } + ProcessState::Sleeping => ProcessState::Running(0), + _ => panic!( + "parent process was not ready to be resumed: {:?}", + parent_process.state + ), + }; // Ensure we don't switch back to the same process. unsafe { crate::arch::irq::take_isr_return_pair() }; - ProcessState::Ready(tids | 1 << current_tid) + ProcessState::Debug(tids | 1 << current_tid) } }; {