Skip to content

Commit

Permalink
Kernel: Execute timer handlers outside of irq handler
Browse files Browse the repository at this point in the history
This allows us to do things in timer handlers that involve e.g. scheduling,
such as using the Lock class or unblocking threads.
  • Loading branch information
tomuta authored and awesomekling committed Dec 12, 2020
1 parent 4bbee00 commit 47ede74
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions Kernel/TimerQueue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,19 +272,24 @@ void TimerQueue::fire()

while (timer && timer->now() > timer->m_expires) {
queue.list.remove(timer);
timer->set_queued(false);

m_timers_executing.append(timer);

update_next_timer_due(queue);

lock.unlock();
timer->m_callback();
lock.lock();

m_timers_executing.remove(timer);
timer->set_queued(false);
// Drop the reference we added when queueing the timer
timer->unref();
// Defer executing the timer outside of the irq handler
Processor::current().deferred_call_queue([this, timer]() {
timer->m_callback();
ScopedSpinLock lock(g_timerqueue_lock);
m_timers_executing.remove(timer);
// Drop the reference we added when queueing the timer
timer->unref();
});

lock.lock();
timer = queue.list.head();
}
};
Expand Down

0 comments on commit 47ede74

Please sign in to comment.