From 41aecae58ae5e50256042b8669af37c56c0b72b9 Mon Sep 17 00:00:00 2001 From: wheremyfoodat Date: Sat, 15 Oct 2022 23:37:22 +0300 Subject: [PATCH] [Kernel] Fix threading bug I think --- src/core/kernel/threads.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/core/kernel/threads.cpp b/src/core/kernel/threads.cpp index 8712c5af..fa10a2ea 100644 --- a/src/core/kernel/threads.cpp +++ b/src/core/kernel/threads.cpp @@ -150,9 +150,9 @@ void Kernel::sleepThread(s64 ns) { if (ns < 0) { Helpers::panic("Sleeping a thread for a negative amount of ns"); } else if (ns == 0) { // Used when we want to force a thread switch - // TODO: Does sleep(0) always switch to another thread, or can it return to the same one if it's the highest prio one? - threads[currentThreadIndex].status = ThreadStatus::Ready; - switchToNextThread(); + int curr = currentThreadIndex; + switchToNextThread(); // Mark thread as ready after switching, to avoid switching to the same thread + threads[curr].status = ThreadStatus::Ready; } else { // If we're sleeping for > 0 ns Thread& t = threads[currentThreadIndex]; t.status = ThreadStatus::WaitSleep;