Clean up callback_list, remove sentinel/active/tail, callbacks return bool for removal, register before send
This commit is contained in:
@@ -29,7 +29,7 @@ struct timer_queue {
|
||||
}
|
||||
|
||||
bool cancel(timer_handle h) {
|
||||
if (!h || !h->active) return false;
|
||||
if (!h) return false;
|
||||
list.remove(h);
|
||||
arm();
|
||||
return true;
|
||||
@@ -39,8 +39,8 @@ struct timer_queue {
|
||||
if (!irq_pending) return;
|
||||
irq_pending = false;
|
||||
while (auto* n = list.front()) {
|
||||
if (absolute_time_diff_us(get_absolute_time(), n->value().when) > 0) break;
|
||||
auto fn = std::move(n->value().fn);
|
||||
if (absolute_time_diff_us(get_absolute_time(), n->value.when) > 0) break;
|
||||
auto fn = std::move(n->value.fn);
|
||||
list.remove(n);
|
||||
fn();
|
||||
}
|
||||
@@ -59,6 +59,6 @@ private:
|
||||
if (alarm >= 0) cancel_alarm(alarm);
|
||||
alarm = -1;
|
||||
if (auto* n = list.front())
|
||||
alarm = add_alarm_at(n->value().when, alarm_cb, this, false);
|
||||
alarm = add_alarm_at(n->value.when, alarm_cb, this, false);
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user