From: Scott Worley Date: Tue, 10 Oct 2023 04:29:10 +0000 (-0700) Subject: client: Extract set_send_alarm() X-Git-Tag: v0.1.0~40 X-Git-Url: http://git.scottworley.com/tattlekey/commitdiff_plain/f523aaab2c85c71677a894c76ad7663101b388ed?ds=inline client: Extract set_send_alarm() --- diff --git a/client/tattlekey.c b/client/tattlekey.c index f5306c2..c600448 100644 --- a/client/tattlekey.c +++ b/client/tattlekey.c @@ -55,6 +55,14 @@ static void time_to_send(uint _) { queue_try_add_ignoring_errors(&queue, &e); } +void set_send_alarm(int alarm, uint32_t now, uint32_t next_act_time) { + uint32_t sleep_duration = next_act_time - now; + if (hardware_alarm_set_target(alarm, + make_timeout_time_ms(sleep_duration * 1000))) + signal_error_by_blinking(); + return; +} + void service_sleeps(int alarm, send_t *sleeping_sends, pheap_t *sleeps_heap) { hardware_alarm_cancel(alarm); @@ -64,10 +72,7 @@ void service_sleeps(int alarm, send_t *sleeping_sends, pheap_t *sleeps_heap) { if (act_time == -1) return; if (act_time > now) { - uint32_t sleep_duration = act_time - now; - if (hardware_alarm_set_target( - alarm, make_timeout_time_ms(sleep_duration * 1000))) - signal_error_by_blinking(); + set_send_alarm(alarm, now, act_time); return; } pheap_node_id_t i = ph_remove_head(sleeps_heap, false);