Clean up callback_list, remove sentinel/active/tail, callbacks return bool for removal, register before send

This commit is contained in:
Ian Gulliver
2026-04-11 15:01:37 +09:00
parent 938b4b8a4c
commit 1c8c645878
5 changed files with 66 additions and 72 deletions

View File

@@ -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);
}
};