Skip to content

Commit

Permalink
fixup timer: fixed time calculate
Browse files Browse the repository at this point in the history
Signed-off-by: John Sanpe <[email protected]>
  • Loading branch information
sanpeqf committed Jun 11, 2024
1 parent 8a39121 commit a4ae57d
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions src/event/xdbd_timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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
Expand All @@ -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;
Expand Down

0 comments on commit a4ae57d

Please sign in to comment.