diff --git a/src/timer_itimer.c b/src/timer_itimer.c index 9e56561..248904e 100644 --- a/src/timer_itimer.c +++ b/src/timer_itimer.c @@ -27,15 +27,14 @@ struct tmr_itimer { struct tmr timer; bool expired; bool running; - unsigned total_timers; - unsigned interval; /**< Interval in counts of itimer expirations */ - unsigned time_left; /**< Time left in counts of itimer expirations */ - unsigned time_elapsed; /**< Time elapsed in counts of itimer expirations */ + unsigned interval; /**< Interval in counts of itimer expirations */ + unsigned time_left; /**< Time left in counts of itimer expirations */ + unsigned time_elapsed; /**< Time elapsed in counts of itimer expirations */ struct list list; }; -static struct list *head = NULL; +static struct list head = {.next = &head, .prev = &head}; static unsigned elapsed = 0; static void @@ -89,10 +88,10 @@ tmr_itimer_destroy(struct tmr *t) { struct tmr_itimer *t_i = CONTAINER_OF(t, struct tmr_itimer, timer); - t_i->total_timers--; + list_del(&t_i->list); /* The last timer, closes the door */ - if (--t_i->total_timers == 0) { + if (list_is_empty(&head)) { struct sigaction sa = {0}; sa.sa_handler = SIG_DFL; sigemptyset(&sa.sa_mask); @@ -114,10 +113,8 @@ tmr_itimer_create(void) return NULL; } - static bool first_timer_init = false; - if (!first_timer_init) { + if (list_is_empty(&head)) { struct sigaction sa; - sa.sa_flags = SA_SIGINFO; sa.sa_sigaction = tmr_handler; sigemptyset(&sa.sa_mask); if (sigaction(SIGALRM, &sa, NULL) == -1) { @@ -135,9 +132,6 @@ tmr_itimer_create(void) goto fail; } - t_i->total_timers = 0; - first_timer_init = true; - list_create(&head); } @@ -148,7 +142,6 @@ tmr_itimer_create(void) t_i->timer.expired = tmr_itimer_expired; t_i->running = false; t_i->expired = false; - t_i->total_timers++; list_add(&head, &t_i->list);