summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFreya Murphy <freya@freyacat.org>2025-04-29 10:27:05 -0400
committerFreya Murphy <freya@freyacat.org>2025-04-29 10:27:05 -0400
commita7079cf0f66f01434bf0860c3020bcdbcf267317 (patch)
treefc8a668c4d4e67b6531c0357a1214d2faeb4ae19
parentfmt (diff)
downloadcomus-a7079cf0f66f01434bf0860c3020bcdbcf267317.tar.gz
comus-a7079cf0f66f01434bf0860c3020bcdbcf267317.tar.bz2
comus-a7079cf0f66f01434bf0860c3020bcdbcf267317.zip
dispatch(): wait for a process to schedule
-rw-r--r--kernel/procs.c15
1 files changed, 11 insertions, 4 deletions
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 <comus/drivers/pit.h>
+#include <comus/memory.h>
#include <comus/procs.h>
#include <comus/error.h>
#include <comus/cpu.h>
-#include <comus/memory.h>
+#include <comus/asm.h>
#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, &current_pcb);
- if (status != SUCCESS)
- panic("dispatch queue remove failed, code %d", status);
+ // wait for a process to schedule
+ do {
+ status = pcb_queue_pop(ready, &current_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);