diff options
author | Niels Provos <provos@cvs.openbsd.org> | 2000-11-17 06:34:24 +0000 |
---|---|---|
committer | Niels Provos <provos@cvs.openbsd.org> | 2000-11-17 06:34:24 +0000 |
commit | 557ec0428178f68869924dcd7fc0c67ae8610097 (patch) | |
tree | 5faea3699a8eef75d844dac3763767dd282a5206 /sys/kern | |
parent | 0c55c0d00446e91f9f26ed5e612b35954a073394 (diff) |
calculate timeouts correctly, simpler.
Diffstat (limited to 'sys/kern')
-rw-r--r-- | sys/kern/kern_event.c | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/sys/kern/kern_event.c b/sys/kern/kern_event.c index 73f0f29a0e0..730c5cfc9f2 100644 --- a/sys/kern/kern_event.c +++ b/sys/kern/kern_event.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_event.c,v 1.3 2000/11/17 05:18:44 provos Exp $ */ +/* $OpenBSD: kern_event.c,v 1.4 2000/11/17 06:34:23 provos Exp $ */ /*- * Copyright (c) 1999,2000 Jonathan Lemon <jlemon@FreeBSD.org> @@ -518,7 +518,7 @@ kqueue_scan(struct file *fp, int maxevents, struct kevent *ulistp, { struct kqueue *kq = (struct kqueue *)fp->f_data; struct kevent *kevp; - struct timeval atv, ttv; + struct timeval atv; struct knote *kn, marker; int s, count, timeout, nkev = 0, error = 0; @@ -528,16 +528,20 @@ kqueue_scan(struct file *fp, int maxevents, struct kevent *ulistp, if (tsp != NULL) { TIMESPEC_TO_TIMEVAL(&atv, tsp); + if (tsp->tv_sec == 0 && tsp->tv_nsec == 0) { + /* No timeout, just poll */ + timeout = -1; + goto start; + } if (itimerfix(&atv)) { error = EINVAL; goto done; } - if (tsp->tv_sec == 0 && tsp->tv_nsec == 0) - timeout = -1; - else - timeout = atv.tv_sec > 24 * 60 * 60 ? - 24 * 60 * 60 * hz : hzto(&atv); + + s = splclock(); timeradd(&atv, &time, &atv); + timeout = hzto(&atv); + splx(s); } else { atv.tv_sec = 0; atv.tv_usec = 0; @@ -547,12 +551,9 @@ kqueue_scan(struct file *fp, int maxevents, struct kevent *ulistp, retry: if (atv.tv_sec || atv.tv_usec) { - if (timercmp(&time, &atv, >=)) + timeout = hzto(&atv); + if (timeout <= 0) goto done; - ttv = atv; - timersub(&ttv, &time, &ttv); - timeout = ttv.tv_sec > 24 * 60 * 60 ? - 24 * 60 * 60 * hz : hzto(&ttv); } start: |