diff --git a/Kernel/Arch/i386/CPU.cpp b/Kernel/Arch/i386/CPU.cpp index 099b2092fb..ab9047da87 100644 --- a/Kernel/Arch/i386/CPU.cpp +++ b/Kernel/Arch/i386/CPU.cpp @@ -490,8 +490,10 @@ void handle_irq() } } - if (s_irq_handler[irq]) + if (s_irq_handler[irq]) { s_irq_handler[irq]->handle_irq(); + Scheduler::stop_idling(); + } PIC::eoi(irq); } diff --git a/Kernel/Scheduler.cpp b/Kernel/Scheduler.cpp index ed5ce0eb0c..310f9c2d14 100644 --- a/Kernel/Scheduler.cpp +++ b/Kernel/Scheduler.cpp @@ -575,3 +575,24 @@ void Scheduler::timer_tick(RegisterDump& regs) "orl $0x00004000, (%esp)\n" "popf\n"); } + +static bool s_should_stop_idling = false; + +void Scheduler::stop_idling() +{ + if (current != &s_colonel_process->main_thread()) + return; + + s_should_stop_idling = true; +} + +void Scheduler::idle_loop() +{ + for (;;) { + asm("hlt"); + if (s_should_stop_idling) { + s_should_stop_idling = false; + yield(); + } + } +} diff --git a/Kernel/Scheduler.h b/Kernel/Scheduler.h index bbde794c1c..f69a206020 100644 --- a/Kernel/Scheduler.h +++ b/Kernel/Scheduler.h @@ -30,6 +30,8 @@ public: static Process* colonel(); static bool is_active(); static void beep(); + static void idle_loop(); + static void stop_idling(); template static inline IterationDecision for_each_runnable(Callback); diff --git a/Kernel/init.cpp b/Kernel/init.cpp index fb51883ed0..c8145af2ed 100644 --- a/Kernel/init.cpp +++ b/Kernel/init.cpp @@ -277,8 +277,6 @@ extern "C" [[noreturn]] void init() sti(); - // This now becomes the idle process :^) - for (;;) { - asm("hlt"); - } + Scheduler::idle_loop(); + ASSERT_NOT_REACHED(); }