1
Files
interrupt-handling-using-th…/code/apictimer_trigger.cpp
2023-03-03 15:40:25 +01:00

21 lines
580 B
C++

// Excerpt from the ApicTimer interrupt handler
void ApicTimer::trigger(const InterruptFrame &frame) {
if (cpuId != LocalApic::getId()) {
// Abort if the handler doesn't belong to the current CPU
return;
}
// Increase the "core-local" time
time.addNanoseconds(timerInterval * 1'000'000); // Interval is in milliseconds
// Only the BSP may continue
if (cpuId != 0) {
return;
}
// BSP triggers preemption
if (time.toMilliseconds() % yieldInterval == 0) {
System::getService<SchedulerService>().yield();
}
}