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 <sean@xobs.io>
This commit is contained in:
Sean Cross 2021-08-25 16:03:06 +08:00
parent 1cb86078d5
commit b43366e6ec

View file

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