diff options
author | Francis Dupont <fdupont@isc.org> | 2008-01-03 00:30:14 +0000 |
---|---|---|
committer | Francis Dupont <fdupont@isc.org> | 2008-01-03 00:30:14 +0000 |
commit | be62cf0675d84a35d6ce68f1a7ae4b7521c64834 (patch) | |
tree | 6df2fbb5d267d67ef0a3df86b4934cd0b2e8cf62 /common/dispatch.c | |
parent | 1d9774ab570d77b7f52432c36e64cc7e59c50a59 (diff) | |
download | isc-dhcp-be62cf0675d84a35d6ce68f1a7ae4b7521c64834.tar.gz |
finer granularity timers
Diffstat (limited to 'common/dispatch.c')
-rw-r--r-- | common/dispatch.c | 26 |
1 files changed, 17 insertions, 9 deletions
diff --git a/common/dispatch.c b/common/dispatch.c index 475fad98..bf4c2319 100644 --- a/common/dispatch.c +++ b/common/dispatch.c @@ -40,8 +40,9 @@ static struct timeout *free_timeouts; void set_time(TIME t) { /* Do any outstanding timeouts. */ - if (cur_time != t) { - cur_time = t; + if (cur_tv . tv_sec != t) { + cur_tv . tv_sec = t; + cur_tv . tv_usec = 0; process_outstanding_timeouts ((struct timeval *)0); } } @@ -54,7 +55,9 @@ struct timeval *process_outstanding_timeouts (struct timeval *tvp) another: if (timeouts) { struct timeout *t; - if (timeouts -> when <= cur_time) { + if ((timeouts -> when . tv_sec < cur_tv . tv_sec) || + ((timeouts -> when . tv_sec == cur_tv . tv_sec) && + (timeouts -> when . tv_usec <= cur_tv . tv_usec))) { t = timeouts; timeouts = timeouts -> next; (*(t -> func)) (t -> what); @@ -65,8 +68,8 @@ struct timeval *process_outstanding_timeouts (struct timeval *tvp) goto another; } if (tvp) { - tvp -> tv_sec = timeouts -> when; - tvp -> tv_usec = 0; + tvp -> tv_sec = timeouts -> when . tv_sec; + tvp -> tv_usec = timeouts -> when . tv_usec; } return tvp; } else @@ -93,7 +96,7 @@ void dispatch () } void add_timeout (when, where, what, ref, unref) - TIME when; + struct timeval *when; void (*where) PROTO ((void *)); void *what; tvref_t ref; @@ -137,12 +140,15 @@ void add_timeout (when, where, what, ref, unref) q -> what = what; } - q -> when = when; + q -> when . tv_sec = when -> tv_sec; + q -> when . tv_usec = when -> tv_usec; /* Now sort this timeout into the timeout list. */ /* Beginning of list? */ - if (!timeouts || timeouts -> when > q -> when) { + if (!timeouts || (timeouts -> when . tv_sec > q -> when . tv_sec) || + ((timeouts -> when . tv_sec == q -> when . tv_sec) && + (timeouts -> when . tv_usec > q -> when . tv_usec))) { q -> next = timeouts; timeouts = q; return; @@ -150,7 +156,9 @@ void add_timeout (when, where, what, ref, unref) /* Middle of list? */ for (t = timeouts; t -> next; t = t -> next) { - if (t -> next -> when > q -> when) { + if ((t -> next -> when . tv_sec > q -> when . tv_sec) || + ((t -> next -> when . tv_sec == q -> when . tv_sec) && + (t -> next -> when . tv_usec > q -> when . tv_usec))) { q -> next = t -> next; t -> next = q; return; |