From a4ae57d1ae7b146f63b9173cf8ffa6dd1273451b Mon Sep 17 00:00:00 2001 From: John Sanpe Date: Mon, 10 Jun 2024 12:51:09 +0800 Subject: [PATCH] fixup timer: fixed time calculate Signed-off-by: John Sanpe --- src/event/xdbd_timer.c | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/src/event/xdbd_timer.c b/src/event/xdbd_timer.c index 6cb4dfe..95f5efa 100644 --- a/src/event/xdbd_timer.c +++ b/src/event/xdbd_timer.c @@ -28,11 +28,7 @@ xdbd_first_timer(void) xdbd_timer_t *timer; node = BFDEV_HEAP_ROOT_NODE(&xdbd_timers); - if (node == NULL) { - return NULL; - } - - timer = bfdev_heap_entry(node, xdbd_timer_t, node); + timer = bfdev_heap_entry_safe(node, xdbd_timer_t, node); return timer; } @@ -54,16 +50,15 @@ xdbd_msec_t xdbd_first_timeout(void) { xdbd_timer_t *timer; - xdbd_msec_t timeout; - timer = xdbd_first_timer(); - if (timer == NULL) { + timer = xdbd_first_timer(); + if (timer == NULL) return XDBD_TIMER_INFINITE; - } - timeout = timer->time - xdbd_current_msec; + if (timer->time <= xdbd_current_msec) + return 0; - return (xdbd_msec_t) (timeout > 0 ? timeout : 0); + return timer->time - xdbd_current_msec; } int @@ -81,6 +76,7 @@ xdbd_expire_timers(void) timer = xdbd_first_timer(); xdbd_remove_timer(timer); + BFDEV_BUG_ON(!timer->func); retval = timer->func(timer, timer->pdata); if (retval) return retval;