commit d0238937e1772129fb816963ca1a644c1565eb76
parent 2417dd481983cef1373744b8718c937ca6b03ec2
Author: Roberto E. Vargas Caballero <roberto.vargas@midokura.com>
Date: Wed, 16 Nov 2022 20:02:30 +0100
os9: Fix small issues in sched()
Diffstat:
1 file changed, 16 insertions(+), 7 deletions(-)
diff --git a/src/os9/proc.c b/src/os9/proc.c
@@ -45,6 +45,7 @@ iproc(void)
panic("init task failed");
tp->affinity = -1;
proc = tp;
+ unlock(&proc->m);
}
void
@@ -473,9 +474,6 @@ err:
return NULL;
}
-/*
- * sched must be called without having any task locked
- */
void
sched(void)
{
@@ -483,9 +481,13 @@ sched(void)
int prio;
long long wait, mask;
- if (proc->state == TRUNNING && proc->flags&TLOCK_PREEMP) {
- unlock(&proc->m);
- swtch(&proc->ctx);
+ lock(&proc->m);
+ if (proc->state == TRUNNING) {
+ if (proc->flags&TLOCK_PREEMP) {
+ unlock(&proc->m);
+ swtch(&proc->ctx);
+ }
+ proc->state = TREADY;
}
unlock(&proc->m);
@@ -497,6 +499,7 @@ repeat:
mask = 1ul << cpuid;
for (tp = tasktab; tp < &tasktab[NR_TASKS]; ++tp) {
lock(&tp->m);
+
if (tp->state == TREADY
&& (tp->affinity & mask) != 0
&& tp->prio >= prio
@@ -505,6 +508,7 @@ repeat:
prio = tp->prio;
wait = tp->wait;
}
+
unlock(&tp->m);
}
@@ -514,7 +518,12 @@ repeat:
goto repeat;
}
- proc->state = TRUNNING;
+ proc = new;
+ lock(&proc->m);
unlock(&procm);
+
+ proc->state = TRUNNING;
+ unlock(&proc->m);
+
swtch(&proc->ctx);
}