diff options
author | Artur Grabowski <art@cvs.openbsd.org> | 2002-02-15 15:59:12 +0000 |
---|---|---|
committer | Artur Grabowski <art@cvs.openbsd.org> | 2002-02-15 15:59:12 +0000 |
commit | 052a02d846be0d778d5898fb49bb70cb21948b17 (patch) | |
tree | 1769fa94856332ab6e809641eb90207e90c5d03a /sys | |
parent | 4bb99082b74c820e4665be24e3649e0de5ef569d (diff) |
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')
-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) |