diff options
author | peter <peter@FreeBSD.org> | 1997-05-17 15:42:58 +0000 |
---|---|---|
committer | peter <peter@FreeBSD.org> | 1997-05-17 15:42:58 +0000 |
commit | ef2cb50b1e9a9ec438651344f03c3586e6f86e9e (patch) | |
tree | 502d0c20b016413993192f971474f4e339ae0c0b /lib/libc/gen/usleep.c | |
parent | ee42839b4fac8cfb8cbc3b62ac964db07c6123d0 (diff) | |
download | FreeBSD-src-ef2cb50b1e9a9ec438651344f03c3586e6f86e9e.zip FreeBSD-src-ef2cb50b1e9a9ec438651344f03c3586e6f86e9e.tar.gz |
if nanosleep returns too early, loop. usleep() does not have a return
value, it appears as though the semantics of usleep are that it doesn't
return early. (only in the nanosleep code - the setitimer code does this
already)
Diffstat (limited to 'lib/libc/gen/usleep.c')
-rw-r--r-- | lib/libc/gen/usleep.c | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/lib/libc/gen/usleep.c b/lib/libc/gen/usleep.c index b5effd4..1549173 100644 --- a/lib/libc/gen/usleep.c +++ b/lib/libc/gen/usleep.c @@ -64,13 +64,18 @@ void usleep(useconds) unsigned int useconds; { -#ifdef _THREAD_SAFE +#if defined(_THREAD_SAFE) || defined(USE_NANOSLEEP) struct timespec time_to_sleep; + struct timespec time_remaining; if (useconds) { time_to_sleep.tv_nsec = (useconds % 1000000) * 1000; time_to_sleep.tv_sec = useconds / 1000000; - nanosleep(&time_to_sleep, NULL); + do { + nanosleep(&time_to_sleep, &time_remaining); + time_to_sleep = time_remaining; + } while (time_to_sleep.tv_sec != 0 && + time_to_sleep.tv_nsec != 0); } #else register struct itimerval *itp; |