diff options
author | ache <ache@FreeBSD.org> | 1997-08-12 15:46:05 +0000 |
---|---|---|
committer | ache <ache@FreeBSD.org> | 1997-08-12 15:46:05 +0000 |
commit | 2a8b6ff0575735c02a3779c7b1b83bf56cf70efa (patch) | |
tree | 7482318ec4c1d6e90f9714755b4dd3360b269a89 /lib/libc | |
parent | 3112d8efeef2e6d39d7aacef1cea11f24247c136 (diff) | |
download | FreeBSD-src-2a8b6ff0575735c02a3779c7b1b83bf56cf70efa.zip FreeBSD-src-2a8b6ff0575735c02a3779c7b1b83bf56cf70efa.tar.gz |
Make itimerfix hack better: return the time we can't sleep at once
Diffstat (limited to 'lib/libc')
-rw-r--r-- | lib/libc/gen/sleep.c | 32 |
1 files changed, 20 insertions, 12 deletions
diff --git a/lib/libc/gen/sleep.c b/lib/libc/gen/sleep.c index 6a40d93..485f778 100644 --- a/lib/libc/gen/sleep.c +++ b/lib/libc/gen/sleep.c @@ -43,6 +43,8 @@ static char sccsid[] = "@(#)sleep.c 8.1 (Berkeley) 6/4/93"; #include "pthread_private.h" #endif +#define ITIMERMAX 100000000 + #ifndef _THREAD_SAFE static void sleephandler() @@ -56,6 +58,7 @@ sleep(seconds) unsigned int seconds; { #ifdef _THREAD_SAFE + unsigned int rest = 0; struct timespec time_to_sleep; struct timespec time_remaining; @@ -64,19 +67,22 @@ sleep(seconds) * XXX * Hack to work around itimerfix(9) gratuitously limiting * the acceptable range for a struct timeval.tv_sec to - * <= 100000000. + * <= ITIMERMAX. */ - if (seconds > 100000000) - seconds = 100000000; + if (seconds > ITIMERMAX) { + rest = seconds - ITIMERMAX; + seconds = ITIMERMAX; + } time_to_sleep.tv_sec = seconds; time_to_sleep.tv_nsec = 0; nanosleep(&time_to_sleep, &time_remaining); - seconds = time_remaining.tv_sec; + rest += time_remaining.tv_sec; if (time_remaining.tv_nsec > 0) - seconds++; /* round up */ + rest++; /* round up */ } - return (seconds); + return (rest); #else + unsigned int rest = 0; struct timespec time_to_sleep; struct timespec time_remaining; struct sigaction act, oact; @@ -87,10 +93,12 @@ sleep(seconds) * XXX * Hack to work around itimerfix(9) gratuitously limiting * the acceptable range for a struct timeval.tv_sec to - * <= 100000000. + * <= ITIMERMAX */ - if (seconds > 100000000) - seconds = 100000000; + if (seconds > ITIMERMAX) { + rest = seconds - ITIMERMAX; + seconds = ITIMERMAX; + } time_to_sleep.tv_sec = seconds; time_to_sleep.tv_nsec = 0; @@ -120,10 +128,10 @@ sleep(seconds) sigprocmask(SIG_SETMASK, &omask, (sigset_t *)0); /* return how long is left */ - seconds = time_remaining.tv_sec; + rest += time_remaining.tv_sec; if (time_remaining.tv_nsec > 0) - seconds++; /* round up */ + rest++; /* round up */ } - return (seconds); + return (rest); #endif /* _THREAD_SAFE */ } |