summaryrefslogtreecommitdiff
path: root/src/kernel/proc.c
diff options
context:
space:
mode:
authordzwdz2022-04-21 19:13:33 +0200
committerdzwdz2022-04-21 19:13:33 +0200
commita990307680233460b2243c84002725b05a68b94a (patch)
treebf8129c3dc227e7910026d6f3a42efeb2af8a40a /src/kernel/proc.c
parent0ae12266b7160272fd95875006c6c1b6d6b1dcd2 (diff)
kernel/proc: only expose `process_switch_any()`
other parts of the kernel don't need to care about which process exactly gets switched into
Diffstat (limited to 'src/kernel/proc.c')
-rw-r--r--src/kernel/proc.c21
1 files changed, 12 insertions, 9 deletions
diff --git a/src/kernel/proc.c b/src/kernel/proc.c
index 175377e..bb4509b 100644
--- a/src/kernel/proc.c
+++ b/src/kernel/proc.c
@@ -84,8 +84,7 @@ void process_free(struct process *p) {
kfree(p);
}
-// TODO make process_switch private
-void process_switch(struct process *proc) {
+static _Noreturn void process_switch(struct process *proc) {
assert(proc->state == PS_RUNNING);
if (proc->deathbed) {
process_kill(proc, -1);
@@ -96,13 +95,8 @@ void process_switch(struct process *proc) {
sysexit(proc->regs);
}
-_Noreturn void process_switch_any(void) {
- struct process *found = process_find(PS_RUNNING);
- if (found) process_switch(found);
- process_idle();
-}
-
-_Noreturn void process_idle(void) {
+/** If there are any processes waiting for IRQs, wait with them. Otherwise, shut down */
+static _Noreturn void process_idle(void) {
struct process *procs[16];
size_t len = process_find_multiple(PS_WAITS4IRQ, procs, 16);
@@ -121,6 +115,15 @@ _Noreturn void process_idle(void) {
}
}
+_Noreturn void process_switch_any(void) {
+ if (process_current && process_current->state == PS_RUNNING)
+ process_switch(process_current);
+
+ struct process *found = process_find(PS_RUNNING);
+ if (found) process_switch(found);
+ process_idle();
+}
+
struct process *process_next(struct process *p) {
/* is a weird depth-first search, the search order is:
* 1