summaryrefslogtreecommitdiff
path: root/src/kernel
diff options
context:
space:
mode:
authordzwdz2023-09-17 17:16:43 +0200
committerdzwdz2023-09-17 17:16:43 +0200
commit730a929fffbaaaeb20529962654049fe26dd5dde (patch)
treebb4fe658f7b32147e15512aec4517c0940e90685 /src/kernel
parent4ade8ff9e6c4185ebe45ecfe183668f28e1525b7 (diff)
kernel/proc: inline proc_switch into proc_switch_any
Diffstat (limited to 'src/kernel')
-rw-r--r--src/kernel/proc.c40
1 files changed, 21 insertions, 19 deletions
diff --git a/src/kernel/proc.c b/src/kernel/proc.c
index ee99603..96386df 100644
--- a/src/kernel/proc.c
+++ b/src/kernel/proc.c
@@ -19,7 +19,6 @@ static uint32_t next_pid = 1;
/** Removes a process from the process tree. */
static void proc_forget(Proc *p);
static void proc_free_forgotten(void);
-static _Noreturn void proc_switch(Proc *proc);
Proc *proc_seed(void *data, size_t datalen) {
@@ -452,31 +451,34 @@ static void proc_free_forgotten(void) {
}
}
-static _Noreturn void proc_switch(Proc *proc) {
- assert(proc->state == PS_RUNNING);
- proc_cur = proc;
- pagedir_switch(proc->pages);
- if (proc->execbuf.buf)
- execbuf_run(proc);
- else
- sysexit(proc->regs);
-}
-
_Noreturn void proc_switch_any(void) {
/* At this point there will be no leftover pointers to forgotten
* processes on the stack, so it's safe to free them. */
proc_free_forgotten();
for (;;) {
- if (proc_cur && proc_cur->state == PS_RUNNING)
- proc_switch(proc_cur);
-
- for (Proc *p = proc_first; p; p = proc_next(p, NULL)) {
- if (p->state == PS_RUNNING)
- proc_switch(p);
+ Proc *p = NULL;
+ if (proc_cur && proc_cur->state == PS_RUNNING) {
+ p = proc_cur;
+ } else {
+ for (p = proc_first; p; p = proc_next(p, NULL)) {
+ if (p->state == PS_RUNNING) {
+ break;
+ }
+ }
+ }
+ if (p) {
+ assert(p->state == PS_RUNNING);
+ proc_cur = p;
+ pagedir_switch(p->pages);
+ if (p->execbuf.buf) {
+ execbuf_run(p);
+ } else {
+ sysexit(p->regs);
+ }
+ } else {
+ cpu_pause();
}
-
- cpu_pause();
}
}