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:
@@ -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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user