kernel: Add a kernel_wait_for_event() function to avoid weird calls to kernel_wait in kthreads
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
apio 2023-05-04 23:43:00 +02:00
parent 4a7f68b989
commit 293a992133
Signed by: apio
GPG Key ID: B8A7D06E42258954
4 changed files with 12 additions and 3 deletions

View File

@ -128,10 +128,10 @@ void io_thread()
while (true)
{
u8 scancode;
while (!scancode_queue.try_pop(scancode)) { kernel_wait(0); }
while (!scancode_queue.try_pop(scancode)) kernel_wait_for_event();
char key;
if (Keyboard::decode_scancode(scancode).try_set_value(key)) { ConsoleDevice::did_press_key(key); }
if (Keyboard::decode_scancode(scancode).try_set_value(key)) ConsoleDevice::did_press_key(key);
}
}

View File

@ -30,7 +30,7 @@ void reap_thread()
dying_threads.consume([](Thread* thread) { Scheduler::reap_thread(thread); });
kernel_wait(0);
kernel_wait_for_event();
}
}

View File

@ -365,6 +365,12 @@ void kernel_wait(pid_t pid)
kernel_yield();
}
void kernel_wait_for_event()
{
g_current->state = ThreadState::Waiting;
kernel_yield();
}
[[noreturn]] void kernel_exit()
{
g_current->state = ThreadState::Dying;

View File

@ -56,3 +56,6 @@ extern "C" void kernel_yield();
void kernel_wait(pid_t pid);
void kernel_sleep(u64 ms);
[[noreturn]] void kernel_exit();
// Freezes the current thread until someone else calls wake_up() on this thread.
void kernel_wait_for_event();