kernel: services: implement Debug for ProcessState

This gives us prettier and more useful displays for ProcessState.

Signed-off-by: Sean Cross <sean@xobs.io>
This commit is contained in:
Sean Cross 2021-03-03 21:18:01 +08:00
parent 5a0533d6bc
commit cc4c0f3c58

View file

@ -36,7 +36,7 @@ pub struct SystemServices {
_syscall_depth: usize,
}
#[derive(Debug, Copy, Clone, PartialEq)]
#[derive(Copy, Clone, PartialEq)]
pub enum ProcessState {
/// This is an unallocated, free process
Free,
@ -62,6 +62,20 @@ pub enum ProcessState {
Sleeping,
}
impl core::fmt::Debug for ProcessState {
fn fmt(&self, fmt: &mut core::fmt::Formatter) -> core::result::Result<(), core::fmt::Error> {
use ProcessState::*;
match *self {
Free => write!(fmt, "Free"),
Allocated => write!(fmt, "Allocated"),
Setup(ti) => write!(fmt, "Setup({:?})", ti),
Ready(rt) => write!(fmt, "Ready({:b})", rt),
Running(rt) => write!(fmt, "Running({:b})", rt),
Sleeping => write!(fmt, "Sleeping"),
}
}
}
impl Default for ProcessState {
fn default() -> ProcessState {
ProcessState::Free