diff options
author | /C=EU/ST=EU/CN=Pablo Neira Ayuso/emailAddress=pablo@netfilter.org </C=EU/ST=EU/CN=Pablo Neira Ayuso/emailAddress=pablo@netfilter.org> | 2008-01-14 15:22:24 +0000 |
---|---|---|
committer | /C=EU/ST=EU/CN=Pablo Neira Ayuso/emailAddress=pablo@netfilter.org </C=EU/ST=EU/CN=Pablo Neira Ayuso/emailAddress=pablo@netfilter.org> | 2008-01-14 15:22:24 +0000 |
commit | 6e5b6c91625fd431ac3d1339f55a4aa278ff2604 (patch) | |
tree | 79e087eebf878ff86bc4dd74292c97748f593b15 /src/alarm.c | |
parent | 94aa8b70f2e8cf7cf664d7c0e86a9ebc287010ef (diff) | |
download | conntrack-tools-6e5b6c91625fd431ac3d1339f55a4aa278ff2604.tar.gz conntrack-tools-6e5b6c91625fd431ac3d1339f55a4aa278ff2604.zip |
improve alarm framework based on suggestions from Max Duempel
Diffstat (limited to 'src/alarm.c')
-rw-r--r-- | src/alarm.c | 33 |
1 files changed, 18 insertions, 15 deletions
diff --git a/src/alarm.c b/src/alarm.c index e1d2e24..eb2226b 100644 --- a/src/alarm.c +++ b/src/alarm.c @@ -28,16 +28,6 @@ static LIST_HEAD(alarm_list); -void set_alarm_expiration_secs(struct alarm_list *t, unsigned long expires) -{ - t->tv.tv_sec = expires; -} - -void set_alarm_expiration_usecs(struct alarm_list *t, unsigned long expires) -{ - t->tv.tv_usec = expires; -} - void set_alarm_function(struct alarm_list *t, void (*fcn)(struct alarm_list *a, void *data)) { @@ -51,8 +41,6 @@ void set_alarm_data(struct alarm_list *t, void *data) void init_alarm(struct alarm_list *t) { - INIT_LIST_HEAD(&t->head); - timerclear(&t->tv); t->data = 0; t->function = NULL; @@ -77,14 +65,26 @@ void mod_alarm(struct alarm_list *alarm, unsigned long sc, unsigned long usc) struct timeval tv; list_del(&alarm->head); - INIT_LIST_HEAD(&alarm->head); 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); } -void do_alarm_run(struct timeval *next_alarm) +int get_next_alarm(struct timeval *tv, struct timeval *next_alarm) +{ + struct list_head *i; + struct alarm_list *t; + + list_for_each(i, &alarm_list) { + t = (struct alarm_list *) i; + timersub(&t->tv, tv, next_alarm); + return 1; + } + return 0; +} + +int do_alarm_run(struct timeval *next_alarm) { struct list_head *i, *tmp; struct alarm_list *t; @@ -97,10 +97,13 @@ void do_alarm_run(struct timeval *next_alarm) if (timercmp(&t->tv, &tv, >)) { timersub(&t->tv, &tv, next_alarm); - break; + return 1; } del_alarm(t); t->function(t, t->data); } + + /* check for refreshed alarms to get the next one */ + return get_next_alarm(&tv, next_alarm); } |