Files
bsb2/kernel/thread/idlethread.cc
2026-01-10 17:21:14 +01:00

34 lines
858 B
C++

#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
//dout << "idle ";
LAPIC::Timer::setMasked(false);
} else {
Core::Interrupt::enable();
Guarded g = Guard::enter();
g.vault().scheduler.resume();
}
}
}