diff options
author | peter <peter@FreeBSD.org> | 1997-05-17 11:40:58 +0000 |
---|---|---|
committer | peter <peter@FreeBSD.org> | 1997-05-17 11:40:58 +0000 |
commit | 01e3d5c705d7984f822cc8fd215d9da6c468d568 (patch) | |
tree | 221e25c74bcebcdba5bcaed641b6a934055e0e4a | |
parent | eebddce2d991040a4e2617d137784fd14de84964 (diff) | |
download | FreeBSD-src-01e3d5c705d7984f822cc8fd215d9da6c468d568.zip FreeBSD-src-01e3d5c705d7984f822cc8fd215d9da6c468d568.tar.gz |
Allow conditional use (add -DUSE_NANOSLEEP) to CFLAGS of nanosleep() for
the backend of sleep(3) and usleep(3). It's off by default until the
problem is fixed.
-rw-r--r-- | lib/libc/gen/sleep.c | 37 | ||||
-rw-r--r-- | lib/libc/gen/usleep.c | 30 |
2 files changed, 33 insertions, 34 deletions
diff --git a/lib/libc/gen/sleep.c b/lib/libc/gen/sleep.c index b3dd8b7..a26b97e 100644 --- a/lib/libc/gen/sleep.c +++ b/lib/libc/gen/sleep.c @@ -41,29 +41,36 @@ static char sccsid[] = "@(#)sleep.c 8.1 (Berkeley) 6/4/93"; #ifdef _THREAD_SAFE #include <pthread.h> #include "pthread_private.h" -#else +#endif +#if !defined(_THREAD_SAFE) && !defined(USE_NANOSLEEP) #define setvec(vec, a) \ vec.sv_handler = a; vec.sv_mask = vec.sv_onstack = 0 static int ringring; + +static void +sleephandler() +{ + ringring = 1; +} #endif unsigned int sleep(seconds) unsigned int seconds; { -#ifdef _THREAD_SAFE - struct timespec time_to_sleep; - struct timespec time_remaining; +#if defined(_THREAD_SAFE) || defined(USE_NANOSLEEP) + struct timespec time_to_sleep; + struct timespec time_remaining; - if (seconds) { - time_to_sleep.tv_sec = seconds; - time_to_sleep.tv_nsec = 0; - nanosleep(&time_to_sleep,&time_remaining); - seconds = time_remaining.tv_sec; - } - return(seconds); + if (seconds != 0) { + time_to_sleep.tv_sec = seconds; + time_to_sleep.tv_nsec = 0; + nanosleep(&time_to_sleep, &time_remaining); + seconds = time_remaining.tv_sec; + } + return (seconds); #else register struct itimerval *itp; struct itimerval itv, oitv; @@ -107,11 +114,3 @@ sleep(seconds) return 0; #endif } - -#ifndef _THREAD_SAFE -static void -sleephandler() -{ - ringring = 1; -} -#endif diff --git a/lib/libc/gen/usleep.c b/lib/libc/gen/usleep.c index 9aece6f..b5effd4 100644 --- a/lib/libc/gen/usleep.c +++ b/lib/libc/gen/usleep.c @@ -41,7 +41,9 @@ static char sccsid[] = "@(#)usleep.c 8.1 (Berkeley) 6/4/93"; #ifdef _THREAD_SAFE #include <pthread.h> #include "pthread_private.h" -#else +#endif + +#if !defined(_THREAD_SAFE) && !defined(USE_NANOSLEEP) #define TICK 10000 /* system clock resolution in microseconds */ #define USPS 1000000 /* number of microseconds in a second */ @@ -49,6 +51,12 @@ static char sccsid[] = "@(#)usleep.c 8.1 (Berkeley) 6/4/93"; vec.sv_handler = a; vec.sv_mask = vec.sv_onstack = 0 static int ringring; + +static void +sleephandler() +{ + ringring = 1; +} #endif @@ -57,13 +65,13 @@ usleep(useconds) unsigned int useconds; { #ifdef _THREAD_SAFE - struct timespec time_to_sleep; + struct timespec time_to_sleep; - if (useconds) { - time_to_sleep.tv_nsec = (useconds % 1000000) * 1000; - time_to_sleep.tv_sec = useconds / 1000000; - nanosleep(&time_to_sleep,NULL); - } + if (useconds) { + time_to_sleep.tv_nsec = (useconds % 1000000) * 1000; + time_to_sleep.tv_sec = useconds / 1000000; + nanosleep(&time_to_sleep, NULL); + } #else register struct itimerval *itp; struct itimerval itv, oitv; @@ -106,11 +114,3 @@ usleep(useconds) (void) setitimer(ITIMER_REAL, &oitv, (struct itimerval *)0); #endif } - -#ifndef _THREAD_SAFE -static void -sleephandler() -{ - ringring = 1; -} -#endif |