summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpeter <peter@FreeBSD.org>1997-05-17 15:42:58 +0000
committerpeter <peter@FreeBSD.org>1997-05-17 15:42:58 +0000
commitef2cb50b1e9a9ec438651344f03c3586e6f86e9e (patch)
tree502d0c20b016413993192f971474f4e339ae0c0b
parentee42839b4fac8cfb8cbc3b62ac964db07c6123d0 (diff)
downloadFreeBSD-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)
-rw-r--r--lib/libc/gen/usleep.c9
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;
OpenPOWER on IntegriCloud