Skip net_poll and timers unless their interrupt has fired
This commit is contained in:
@@ -15,6 +15,7 @@ inline bool operator<(const timer_entry& a, const timer_entry& b) {
|
||||
struct timer_queue {
|
||||
sorted_list<timer_entry, 16> queue;
|
||||
alarm_id_t alarm = -1;
|
||||
volatile bool irq_pending = false;
|
||||
|
||||
void schedule(absolute_time_t when, std::function<void()> fn) {
|
||||
queue.insert({when, std::move(fn)});
|
||||
@@ -26,6 +27,8 @@ struct timer_queue {
|
||||
}
|
||||
|
||||
void run() {
|
||||
if (!irq_pending) return;
|
||||
irq_pending = false;
|
||||
while (!queue.empty()) {
|
||||
auto& front = queue.front();
|
||||
if (absolute_time_diff_us(get_absolute_time(), front.when) > 0) break;
|
||||
@@ -39,12 +42,15 @@ struct timer_queue {
|
||||
bool empty() const { return queue.empty(); }
|
||||
|
||||
private:
|
||||
static int64_t alarm_cb(alarm_id_t, void*) { return 0; }
|
||||
static int64_t alarm_cb(alarm_id_t, void* user_data) {
|
||||
static_cast<timer_queue*>(user_data)->irq_pending = true;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void arm() {
|
||||
if (alarm >= 0) cancel_alarm(alarm);
|
||||
alarm = -1;
|
||||
if (!queue.empty())
|
||||
alarm = add_alarm_at(queue.front().when, alarm_cb, nullptr, false);
|
||||
alarm = add_alarm_at(queue.front().when, alarm_cb, this, false);
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user