From 42255e6c0566b82ba6035a012785d7d3e1908694 Mon Sep 17 00:00:00 2001 From: John Sanpe Date: Sat, 18 Jan 2025 22:39:42 +0800 Subject: [PATCH] feat timer: added check pending function Signed-off-by: John Sanpe --- include/bfenv/eproc.h | 7 +++++++ src/eproc/timer.c | 2 ++ 2 files changed, 9 insertions(+) diff --git a/include/bfenv/eproc.h b/include/bfenv/eproc.h index 101e092..ce4053c 100644 --- a/include/bfenv/eproc.h +++ b/include/bfenv/eproc.h @@ -60,6 +60,7 @@ struct bfenv_eproc_event { struct bfenv_eproc_timer { bfdev_heap_node_t node; time_t time; + bool pending; struct bfenv_eproc *eproc; bfenv_eproc_timer_cb_t func; @@ -83,6 +84,12 @@ BFDEV_BITFLAGS(bfenv_eproc_write, __BFENV_EPROC_WRITE) BFDEV_BITFLAGS(bfenv_eproc_edge, __BFENV_EPROC_EDGE) BFDEV_BITFLAGS(bfenv_eproc_blocking, __BFENV_EPROC_BLOCKING) +static __bfdev_always_inline bool +bfenv_eproc_timer_pending(const bfenv_eproc_timer_t *timer) +{ + return timer->pending; +} + extern int bfenv_eproc_event_add(bfenv_eproc_t *eproc, bfenv_eproc_event_t *event); diff --git a/src/eproc/timer.c b/src/eproc/timer.c index 6616fec..cf10e20 100644 --- a/src/eproc/timer.c +++ b/src/eproc/timer.c @@ -33,6 +33,7 @@ eproc_timer_first(bfenv_eproc_t *eproc) static void eproc_timer_add(bfenv_eproc_t *eproc, bfenv_eproc_timer_t *timer, bfenv_msec_t timeout) { + timer->pending = true; timer->time = eproc->current_msec + timeout; bfdev_heap_insert(&eproc->timers, &timer->node, timer_cmp, NULL); } @@ -40,6 +41,7 @@ eproc_timer_add(bfenv_eproc_t *eproc, bfenv_eproc_timer_t *timer, bfenv_msec_t t static void eproc_timer_remove(bfenv_eproc_t *eproc, bfenv_eproc_timer_t *timer) { + timer->pending = false; bfdev_heap_remove(&eproc->timers, &timer->node); }