From a7079cf0f66f01434bf0860c3020bcdbcf267317 Mon Sep 17 00:00:00 2001 From: Freya Murphy Date: Tue, 29 Apr 2025 10:27:05 -0400 Subject: dispatch(): wait for a process to schedule --- kernel/procs.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'kernel/procs.c') diff --git a/kernel/procs.c b/kernel/procs.c index 5b03e73..1668bef 100644 --- a/kernel/procs.c +++ b/kernel/procs.c @@ -1,8 +1,9 @@ #include +#include #include #include #include -#include +#include #define PCB_QUEUE_EMPTY(q) ((q)->head == NULL) @@ -467,11 +468,17 @@ void schedule(struct pcb *pcb) __attribute__((noreturn)) void dispatch(void) { + int status; + assert(current_pcb == NULL, "dispatch: current process is not null"); - int status = pcb_queue_pop(ready, ¤t_pcb); - if (status != SUCCESS) - panic("dispatch queue remove failed, code %d", status); + // wait for a process to schedule + do { + status = pcb_queue_pop(ready, ¤t_pcb); + if (status == SUCCESS) + break; + int_wait(); + } while (1); // set the process up for success current_pcb->regs.cr3 = (uint64_t)mem_ctx_pgdir(current_pcb->memctx); -- cgit v1.2.3-freya