kernel: Add a convenience wake_up() function

This commit is contained in:
apio 2023-05-04 23:35:54 +02:00
parent 3a1c22bb93
commit 4a7f68b989
Signed by: apio
GPG Key ID: B8A7D06E42258954
5 changed files with 10 additions and 5 deletions

View File

@ -149,7 +149,7 @@ extern "C" void arch_interrupt_entry(Registers* regs)
{ {
u8 scancode = IO::inb(0x60); u8 scancode = IO::inb(0x60);
scancode_queue.try_push(scancode); scancode_queue.try_push(scancode);
g_io_thread->state = ThreadState::Runnable; g_io_thread->wake_up();
pic_eoi(regs); pic_eoi(regs);
} }
else if (regs->isr == 66) // System call else if (regs->isr == 66) // System call

View File

@ -69,7 +69,7 @@ Result<void> init()
// Disable console logging before transferring control to userspace. // Disable console logging before transferring control to userspace.
setup_log(log_debug_enabled(), log_serial_enabled(), false); setup_log(log_debug_enabled(), log_serial_enabled(), false);
init_thread->state = ThreadState::Runnable; init_thread->wake_up();
kernel_exit(); kernel_exit();
} }

View File

@ -19,7 +19,7 @@ Result<u64> sys_exit(Registers*, SyscallArgs args)
if (child == -1 || child == (pid_t)current->id) if (child == -1 || child == (pid_t)current->id)
{ {
parent->child_being_waited_for = (pid_t)current->id; parent->child_being_waited_for = (pid_t)current->id;
parent->state = ThreadState::Runnable; parent->wake_up();
} }
} }

View File

@ -66,7 +66,7 @@ namespace Scheduler
void signal_reap_thread() void signal_reap_thread()
{ {
if (g_reap) g_reap->state = ThreadState::Runnable; if (g_reap) g_reap->wake_up();
} }
Result<Thread*> new_kernel_thread_impl(Thread* thread, const char* name) Result<Thread*> new_kernel_thread_impl(Thread* thread, const char* name)
@ -268,7 +268,7 @@ namespace Scheduler
{ {
if (thread->state == ThreadState::Sleeping) if (thread->state == ThreadState::Sleeping)
{ {
if (--thread->sleep_ticks_left == 0) thread->state = ThreadState::Runnable; if (--thread->sleep_ticks_left == 0) thread->wake_up();
} }
} }

View File

@ -100,6 +100,11 @@ struct Thread : public LinkedListNode<Thread>
return state == ThreadState::Idle; return state == ThreadState::Idle;
} }
void wake_up()
{
state = ThreadState::Runnable;
}
void init_regs_kernel(); void init_regs_kernel();
void init_regs_user(); void init_regs_user();