From a3f3fce1466938522e3ab8a722486ccf20333aa5 Mon Sep 17 00:00:00 2001 From: "/C=EU/ST=EU/CN=Pablo Neira Ayuso/emailAddress=pablo@netfilter.org" Date: Mon, 14 Jan 2008 16:56:58 +0000 Subject: make sure add_alarm() and mod_alarm() insert sorted by due time --- src/alarm.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'src/alarm.c') diff --git a/src/alarm.c b/src/alarm.c index eb2226b..6aac4a3 100644 --- a/src/alarm.c +++ b/src/alarm.c @@ -46,13 +46,29 @@ void init_alarm(struct alarm_list *t) t->function = NULL; } +void __add_alarm(struct alarm_list *alarm) +{ + struct list_head *i; + struct alarm_list *t; + + list_for_each(i, &alarm_list) { + t = (struct alarm_list *) i; + + if (timercmp(&alarm->tv, &t->tv, <)) { + list_add_tail(&alarm->head, &t->head); + return; + } + } + list_add_tail(&alarm->head, &alarm_list); +} + void add_alarm(struct alarm_list *alarm) { struct timeval tv; gettimeofday(&tv, NULL); alarm->tv.tv_sec += tv.tv_sec; - list_add_tail(&alarm->head, &alarm_list); + __add_alarm(alarm); } void del_alarm(struct alarm_list *alarm) @@ -68,7 +84,7 @@ void mod_alarm(struct alarm_list *alarm, unsigned long sc, unsigned long usc) gettimeofday(&tv, NULL); alarm->tv.tv_sec = tv.tv_sec + sc; alarm->tv.tv_usec = tv.tv_usec + usc; - list_add_tail(&alarm->head, &alarm_list); + __add_alarm(alarm); } int get_next_alarm(struct timeval *tv, struct timeval *next_alarm) -- cgit v1.2.3