summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorQuinn Stephens <quinn@osmora.org>2024-03-07 13:35:04 -0500
committerIan Moffett <ian@osmora.org>2024-03-07 19:22:27 -0500
commit59df7bdadbfd50bfaf95cde442c7380cce535254 (patch)
tree2545d2a4646f7758fbc59e8de66d09723ac6a7ae
parentf5e48e94a2f4d4bbd6e5628c7f2afafc6dbcc459 (diff)
kern: sched: Refactor queue and ctx switch code
Signed-off-by: Quinn Stephens <quinn@osmora.org> Signed-off-by: Ian Moffett <ian@osmora.org>
-rw-r--r--sys/kern/kern_sched.c18
1 files changed, 7 insertions, 11 deletions
diff --git a/sys/kern/kern_sched.c b/sys/kern/kern_sched.c
index f61c592..266ce39 100644
--- a/sys/kern/kern_sched.c
+++ b/sys/kern/kern_sched.c
@@ -97,13 +97,11 @@ sched_dequeue_td(void)
spinlock_acquire(&tdq_lock);
- if (TAILQ_EMPTY(&td_queue)) {
- goto done;
+ if (!TAILQ_EMPTY(&td_queue)) {
+ td = TAILQ_FIRST(&td_queue);
+ TAILQ_REMOVE(&td_queue, td, link);
}
- td = TAILQ_FIRST(&td_queue);
- TAILQ_REMOVE(&td_queue, td, link);
-done:
spinlock_release(&tdq_lock);
return td;
}
@@ -174,11 +172,9 @@ sched_context_switch(struct trapframe *tf)
* If we have no threads, we should not
* preempt at all.
*/
- if (nthread == 0) {
- goto done;
- } else if ((next_td = sched_dequeue_td()) == NULL) {
- /* Empty */
- goto done;
+ if (nthread == 0 || (next_td = sched_dequeue_td()) == NULL) {
+ sched_oneshot();
+ return;
}
if (state->td != NULL) {
@@ -196,7 +192,7 @@ sched_context_switch(struct trapframe *tf)
if (td != NULL) {
sched_enqueue_td(td);
}
-done:
+
sched_oneshot();
}