simplify timeout handling code in kqueue_scan()

This commit is contained in:
jdolecek 2003-02-21 20:57:09 +00:00
parent 5a426e7c8f
commit b4a06ab5af

View File

@ -1,4 +1,4 @@
/* $NetBSD: kern_event.c,v 1.8 2003/02/04 09:02:05 jdolecek Exp $ */ /* $NetBSD: kern_event.c,v 1.9 2003/02/21 20:57:09 jdolecek Exp $ */
/*- /*-
* Copyright (c) 1999,2000,2001 Jonathan Lemon <jlemon@FreeBSD.org> * Copyright (c) 1999,2000,2001 Jonathan Lemon <jlemon@FreeBSD.org>
* All rights reserved. * All rights reserved.
@ -887,7 +887,7 @@ kqueue_scan(struct file *fp, size_t maxevents, struct kevent *ulistp,
if (count == 0) if (count == 0)
goto done; goto done;
if (tsp != NULL) { /* timeout supplied */ if (tsp) { /* timeout supplied */
TIMESPEC_TO_TIMEVAL(&atv, tsp); TIMESPEC_TO_TIMEVAL(&atv, tsp);
if (itimerfix(&atv)) { if (itimerfix(&atv)) {
error = EINVAL; error = EINVAL;
@ -896,26 +896,23 @@ kqueue_scan(struct file *fp, size_t maxevents, struct kevent *ulistp,
s = splclock(); s = splclock();
timeradd(&atv, &time, &atv); /* calc. time to wait until */ timeradd(&atv, &time, &atv); /* calc. time to wait until */
splx(s); splx(s);
if (tsp->tv_sec == 0 && tsp->tv_nsec < 1000 /*<1us*/) timeout = hzto(&atv);
timeout = -1; /* perform a poll */ if (timeout <= 0)
else timeout = -1; /* do poll */
timeout = hzto(&atv); /* calculate hz till timeout */
} else { } else {
atv.tv_sec = 0; /* no timeout, wait forever */ /* no timeout, wait forever */
atv.tv_usec = 0;
timeout = 0; timeout = 0;
} }
goto start; goto start;
retry: retry:
if (atv.tv_sec || atv.tv_usec) { /* timeout requested */ if (tsp) {
s = splclock(); /*
if (timercmp(&time, &atv, >=)) { * We have to recalculate the timeout on every retry.
splx(s); */
goto done; /* timeout reached */ timeout = hzto(&atv);
} if (timeout <= 0)
splx(s); goto done;
timeout = hzto(&atv); /* recalc. timeout remaining */
} }
start: start: