Skip to content

Commit

Permalink
Add more to itimer
Browse files Browse the repository at this point in the history
Signed-off-by: Ioannis Konstantelias <ikonstadel@gmail.com>
  • Loading branch information
gon1332 committed Feb 13, 2025
1 parent 35f7307 commit 91ab630
Showing 1 changed file with 7 additions and 14 deletions.
21 changes: 7 additions & 14 deletions src/timer_itimer.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand All @@ -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) {
Expand All @@ -135,9 +132,6 @@ tmr_itimer_create(void)
goto fail;
}

t_i->total_timers = 0;
first_timer_init = true;

list_create(&head);
}

Expand All @@ -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);

Expand Down

0 comments on commit 91ab630

Please sign in to comment.