#include "idlethread.h" #include "../arch/core.h" #include "../arch/lapic.h" #include "../debug/output.h" #include "../interrupt/guard.h" #include "../thread/scheduler.h" void IdleThread::action() { while (true) { Core::Interrupt::disable(); if (Guard::unsafeConstAccess() .scheduler.isEmpty()) { // XXX: not a fan ... // To save energy we can disable the timer on a core as soon as no // clock needs to be managed. This function is called from the idle // loop. bool can_sleep = !Guard::unsafeConstAccess().bellringer.bellPending(); if (can_sleep) { LAPIC::Timer::setMasked(true); } Core::idle(); // We woke up. Start ticking again LAPIC::Timer::setMasked(false); } else { Core::Interrupt::enable(); Guarded g = Guard::enter(); g.vault().scheduler.resume(); } } }