Skip to content

Commit

Permalink
feat timer: added check pending function
Browse files Browse the repository at this point in the history
Signed-off-by: John Sanpe <[email protected]>
  • Loading branch information
sanpeqf committed Jan 18, 2025
1 parent 80726a4 commit 42255e6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
7 changes: 7 additions & 0 deletions include/bfenv/eproc.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);

Expand Down
2 changes: 2 additions & 0 deletions src/eproc/timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,15 @@ 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);
}

static void
eproc_timer_remove(bfenv_eproc_t *eproc, bfenv_eproc_timer_t *timer)
{
timer->pending = false;
bfdev_heap_remove(&eproc->timers, &timer->node);
}

Expand Down

0 comments on commit 42255e6

Please sign in to comment.