From 44bbb86a75043b38bdfb9ed6ff4be0764e3fc905 Mon Sep 17 00:00:00 2001 From: Ian Moffett Date: Mon, 13 Oct 2025 14:53:04 -0400 Subject: kern: proc: Implement process sleeping and waking Signed-off-by: Ian Moffett --- src/sys/os/os_proc.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) (limited to 'src/sys/os/os_proc.c') diff --git a/src/sys/os/os_proc.c b/src/sys/os/os_proc.c index 971a6c0..4ee4fd8 100644 --- a/src/sys/os/os_proc.c +++ b/src/sys/os/os_proc.c @@ -168,6 +168,43 @@ proc_clear_ranges(struct proc *proc) } } +/* + * Put a process to sleep + */ +int +proc_sleep(struct proc *proc) +{ + struct pcore *core = this_core(); + + if (proc == NULL || core == NULL) { + return -EINVAL; + } + + proc->flags |= PROC_SLEEPING; + md_proc_sleep(); + return 0; +} + +/* + * Wake up a process + */ +int +proc_wake(struct proc *proc) +{ + struct pcore *core = cpu_sched(); + + if (core == NULL || proc == NULL) { + return -1; + } + + if (!ISSET(proc->flags, PROC_SLEEPING)) { + return -1; + } + + proc->flags &= ~PROC_SLEEPING; + return 0; +} + /* * MI proc init code */ @@ -273,10 +310,21 @@ proc_add_range(struct proc *procp, vaddr_t va, paddr_t pa, size_t len) int proc_kill(struct proc *procp, int status) { + struct proc *self = proc_self(); + if (procp == NULL) { return -EINVAL; } + /* + * Try to wake up our parent if they are sleeping + * at all. + */ + if (self->pid == procp->pid) { + if (self->parent != NULL) + proc_wake(self->parent); + } + procp->flags |= PROC_EXITING; proc_clear_ranges(procp); TAILQ_REMOVE(&procq, procp, lup_link); @@ -337,6 +385,7 @@ proc_spawn(const char *path, struct penv_blk *envbp) } proc->envblk = envbp; + proc->parent = proc_self(); md_set_ip(proc, elf.entrypoint); sched_enq(&core->scq, proc); -- cgit v1.2.3