Eliminate std::function: fn-pointer callbacks, per-test test_state structs, udp.cpp with link-time udp::client::handler, udp::address

This commit is contained in:
Ian Gulliver
2026-04-19 00:32:13 -07:00
parent 40f7fb5941
commit 32044a5cbd
11 changed files with 378 additions and 285 deletions

View File

@@ -1,11 +1,10 @@
#pragma once
#include <functional>
#include "pico/time.h"
#include "callback_list.h"
struct timer_entry {
absolute_time_t when;
std::function<void()> fn;
void (*fn)() = nullptr;
};
using timer_handle = callback_list<timer_entry, 16>::node*;
@@ -15,8 +14,8 @@ struct timer_queue {
alarm_id_t alarm = -1;
volatile bool irq_pending = false;
timer_handle schedule(absolute_time_t when, std::function<void()> fn) {
auto* n = list.insert_sorted({when, std::move(fn)},
timer_handle schedule(absolute_time_t when, void (*fn)()) {
auto* n = list.insert_sorted({when, fn},
[](const timer_entry& a, const timer_entry& b) {
return absolute_time_diff_us(b.when, a.when) < 0;
});
@@ -24,8 +23,8 @@ struct timer_queue {
return n;
}
timer_handle schedule_ms(uint32_t ms, std::function<void()> fn) {
return schedule(make_timeout_time_ms(ms), std::move(fn));
timer_handle schedule_ms(uint32_t ms, void (*fn)()) {
return schedule(make_timeout_time_ms(ms), fn);
}
bool cancel(timer_handle h) {
@@ -40,7 +39,7 @@ struct timer_queue {
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);
auto fn = n->value.fn;
list.remove(n);
fn();
}