From 1cebe547c00dbe8a070bfd25e49bfd4bb21e1798 Mon Sep 17 00:00:00 2001 From: Drew Galbraith Date: Mon, 19 Jun 2023 21:47:37 -0700 Subject: [PATCH] [zion] Allow the sleep thread to be preempted. We can't yield it when the next thread is unblocked for now because it may still be holding a lock that the prempted thread is waiting on. --- zion/scheduler/scheduler.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/zion/scheduler/scheduler.cpp b/zion/scheduler/scheduler.cpp index b274cc7..cec378c 100644 --- a/zion/scheduler/scheduler.cpp +++ b/zion/scheduler/scheduler.cpp @@ -42,7 +42,14 @@ void Scheduler::Preempt() { if (current_thread_ == sleep_thread_) { // Sleep should never be preempted. (We should yield it if another thread // becomes scheduleable). - asm volatile("sti"); + // FIXME: We should yield these threads instead of preempting them. + if (runnable_threads_.size() > 0) { + current_thread_ = runnable_threads_.PopFront(); + sleep_thread_->SetState(Thread::RUNNABLE); + SwapToCurrent(*sleep_thread_); + } else { + asm volatile("sti"); + } return; }