diff --git a/kernel/src/arch/x86_64/CPU.cpp b/kernel/src/arch/x86_64/CPU.cpp index 08d132db..30a28324 100644 --- a/kernel/src/arch/x86_64/CPU.cpp +++ b/kernel/src/arch/x86_64/CPU.cpp @@ -149,7 +149,7 @@ extern "C" void arch_interrupt_entry(Registers* regs) { u8 scancode = IO::inb(0x60); scancode_queue.try_push(scancode); - g_io_thread->state = ThreadState::Runnable; + g_io_thread->wake_up(); pic_eoi(regs); } else if (regs->isr == 66) // System call diff --git a/kernel/src/main.cpp b/kernel/src/main.cpp index d7219651..26fd999a 100644 --- a/kernel/src/main.cpp +++ b/kernel/src/main.cpp @@ -69,7 +69,7 @@ Result init() // Disable console logging before transferring control to userspace. setup_log(log_debug_enabled(), log_serial_enabled(), false); - init_thread->state = ThreadState::Runnable; + init_thread->wake_up(); kernel_exit(); } diff --git a/kernel/src/sys/exit.cpp b/kernel/src/sys/exit.cpp index 6f19a6d8..0a6ad43d 100644 --- a/kernel/src/sys/exit.cpp +++ b/kernel/src/sys/exit.cpp @@ -19,7 +19,7 @@ Result sys_exit(Registers*, SyscallArgs args) if (child == -1 || child == (pid_t)current->id) { parent->child_being_waited_for = (pid_t)current->id; - parent->state = ThreadState::Runnable; + parent->wake_up(); } } diff --git a/kernel/src/thread/Scheduler.cpp b/kernel/src/thread/Scheduler.cpp index 72800046..cfbf8f20 100644 --- a/kernel/src/thread/Scheduler.cpp +++ b/kernel/src/thread/Scheduler.cpp @@ -66,7 +66,7 @@ namespace Scheduler void signal_reap_thread() { - if (g_reap) g_reap->state = ThreadState::Runnable; + if (g_reap) g_reap->wake_up(); } Result new_kernel_thread_impl(Thread* thread, const char* name) @@ -268,7 +268,7 @@ namespace Scheduler { if (thread->state == ThreadState::Sleeping) { - if (--thread->sleep_ticks_left == 0) thread->state = ThreadState::Runnable; + if (--thread->sleep_ticks_left == 0) thread->wake_up(); } } diff --git a/kernel/src/thread/Thread.h b/kernel/src/thread/Thread.h index 8cbb895a..e50fa45e 100644 --- a/kernel/src/thread/Thread.h +++ b/kernel/src/thread/Thread.h @@ -100,6 +100,11 @@ struct Thread : public LinkedListNode return state == ThreadState::Idle; } + void wake_up() + { + state = ThreadState::Runnable; + } + void init_regs_kernel(); void init_regs_user();