diff options
| author | 2002-02-15 15:59:11 +0000 | |
|---|---|---|
| committer | 2002-02-15 15:59:11 +0000 | |
| commit | ffb911026a081dfdf4cbb7f6310f3ea50d6363b5 (patch) | |
| tree | 1d13bbc98e06f7c19cb1d137cb3688c8c3ce3933 /sys/kern/kern_time.c | |
| parent | pf only uses seconds for time measuring. There is no need to call microtime (diff) | |
| download | wireguard-openbsd-ffb911026a081dfdf4cbb7f6310f3ea50d6363b5.tar.xz wireguard-openbsd-ffb911026a081dfdf4cbb7f6310f3ea50d6363b5.zip | |
Don't get confused in nanosleep(2) when the time changes.
There is no need to use 'time' when we can use 'mono_time'.
(oh and now it's faster too)
Diffstat (limited to 'sys/kern/kern_time.c')
| -rw-r--r-- | sys/kern/kern_time.c | 34 |
1 files changed, 17 insertions, 17 deletions
diff --git a/sys/kern/kern_time.c b/sys/kern/kern_time.c index e3ce8ff76a2..8c02038ce43 100644 --- a/sys/kern/kern_time.c +++ b/sys/kern/kern_time.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_time.c,v 1.25 2001/12/12 19:06:47 nordin Exp $ */ +/* $OpenBSD: kern_time.c,v 1.26 2002/02/15 15:59:11 art Exp $ */ /* $NetBSD: kern_time.c,v 1.20 1996/02/18 11:57:06 fvdl Exp $ */ /* @@ -189,13 +189,13 @@ sys_nanosleep(p, v, retval) register_t *retval; { static int nanowait; - register struct sys_nanosleep_args/* { + struct sys_nanosleep_args/* { syscallarg(const struct timespec *) rqtp; syscallarg(struct timespec *) rmtp; } */ *uap = v; struct timespec rqt; struct timespec rmt; - struct timeval atv, utv; + struct timeval stv, etv, atv; int error, s, timo; error = copyin((const void *)SCARG(uap, rqtp), (void *)&rqt, @@ -207,15 +207,13 @@ sys_nanosleep(p, v, retval) if (itimerfix(&atv)) return (EINVAL); - s = splclock(); - timeradd(&atv,&time,&atv); - timo = hzto(&atv); - splx(s); - /* - * Avoid inadvertantly sleeping forever - */ - if (timo <= 0) - timo = 1; + if (SCARG(uap, rmtp)) { + s = splclock(); + stv = mono_time; + splx(s); + } + + timo = tvtohz(&atv); error = tsleep(&nanowait, PWAIT | PCATCH, "nanosleep", timo); if (error == ERESTART) @@ -227,14 +225,16 @@ sys_nanosleep(p, v, retval) int error; s = splclock(); - utv = time; + etv = mono_time; splx(s); - timersub(&atv, &utv, &utv); - if (utv.tv_sec < 0) - timerclear(&utv); + timersub(&etv, &stv, &stv); + timersub(&stv, &atv, &atv); + + if (atv.tv_sec < 0) + timerclear(&atv); - TIMEVAL_TO_TIMESPEC(&utv, &rmt); + TIMEVAL_TO_TIMESPEC(&atv, &rmt); error = copyout((void *)&rmt, (void *)SCARG(uap,rmtp), sizeof(rmt)); if (error) |
