[Kernel] Fix threading bug I think

This commit is contained in:
wheremyfoodat 2022-10-15 23:37:22 +03:00
parent 72132cd97e
commit 41aecae58a

View file

@ -150,9 +150,9 @@ void Kernel::sleepThread(s64 ns) {
if (ns < 0) { if (ns < 0) {
Helpers::panic("Sleeping a thread for a negative amount of ns"); Helpers::panic("Sleeping a thread for a negative amount of ns");
} else if (ns == 0) { // Used when we want to force a thread switch } 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? int curr = currentThreadIndex;
threads[currentThreadIndex].status = ThreadStatus::Ready; switchToNextThread(); // Mark thread as ready after switching, to avoid switching to the same thread
switchToNextThread(); threads[curr].status = ThreadStatus::Ready;
} else { // If we're sleeping for > 0 ns } else { // If we're sleeping for > 0 ns
Thread& t = threads[currentThreadIndex]; Thread& t = threads[currentThreadIndex];
t.status = ThreadStatus::WaitSleep; t.status = ThreadStatus::WaitSleep;