diff options
author | Quinn Stephens <quinn@osmora.org> | 2024-03-07 13:35:04 -0500 |
---|---|---|
committer | Ian Moffett <ian@osmora.org> | 2024-03-07 19:22:27 -0500 |
commit | 59df7bdadbfd50bfaf95cde442c7380cce535254 (patch) | |
tree | 2545d2a4646f7758fbc59e8de66d09723ac6a7ae /sys | |
parent | f5e48e94a2f4d4bbd6e5628c7f2afafc6dbcc459 (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>
Diffstat (limited to 'sys')
-rw-r--r-- | sys/kern/kern_sched.c | 18 |
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(); } |