CHECK_INCLUDE_FILE("linux/futex.h" HAVE_FUTEX_H)
CHECK_FUNCTION_EXISTS(gettimeofday HAVE_GETTIMEOFDAY)
-CHECK_FUNCTION_EXISTS(usleep HAVE_USLEEP)
+CHECK_FUNCTION_EXISTS(nanosleep HAVE_NANOSLEEP)
CHECK_FUNCTION_EXISTS(getdtablesize HAVE_GETDTABLESIZE)
CHECK_FUNCTION_EXISTS(sysconf HAVE_SYSCONF)
CHECK_FUNCTION_EXISTS(readv HAVE_READV)
message("")
message("HAVE_GETTIMEOFDAY ...........: ${HAVE_GETTIMEOFDAY}")
- message("HAVE_USLEEP .................: ${HAVE_USLEEP}")
+ message("HAVE_NANOSLEEP ..............: ${HAVE_NANOSLEEP}")
message("HAVE_GETDTABLESIZE ..........: ${HAVE_GETDTABLESIZE}")
message("HAVE_SYSCONF ................: ${HAVE_SYSCONF}")
message("HAVE_READV ..................: ${HAVE_READV}")
/* Define to 1 if you have the <unistd.h> header file. */
#cmakedefine HAVE_UNISTD_H @HAVE_UNISTD_H@
-/* Define to 1 if you have the `usleep' function. */
-#cmakedefine HAVE_USLEEP @HAVE_USLEEP@
+/* Define to 1 if you have the `nanosleep' function. */
+#cmakedefine HAVE_NANOSLEEP @HAVE_NANOSLEEP@
/* Define to 1 if you have the <valgrind/valgrind.h> header file. */
#cmakedefine HAVE_VALGRIND_VALGRIND_H @HAVE_VALGRIND_VALGRIND_H@
#undef HAVE_SYSCONF
#endif
-/* No `usleep' function. */
-#if defined(HAVE_USLEEP)
-#undef HAVE_USLEEP
+/* No `nanosleep' function. */
+#if defined(HAVE_NANOSLEEP)
+#undef HAVE_NANOSLEEP
#endif
/* The compiler has the `vsnprintf' function. */
#undef HAVE_SYSCONF
#endif
-/* No `usleep' function. */
-#if defined(HAVE_USLEEP)
-#undef HAVE_USLEEP
+/* No `nanosleep' function. */
+#if defined(HAVE_NANOSLEEP)
+#undef HAVE_NANOSLEEP
#endif
/* The compiler has the `vsnprintf' function. */
#ifdef _XBT_WIN32
Sleep((floor(sec) * 1000) + ((sec - floor(sec)) * 1000));
-#elif HAVE_USLEEP
- sleep(sec);
- (void) usleep((sec - floor(sec)) * 1000000);
-
-#else /* don't have usleep. Use select to sleep less than one second */
+#elif HAVE_NANOSLEEP
+ struct timespec ts;
+ ts.tv_sec = sec;
+ ts.tv_nsec = (sec - floor(sec)) * 1e9;
+ nanosleep (&ts, NULL);
+#else /* don't have nanosleep. Use select to sleep less than one second */
struct timeval timeout;
-
timeout.tv_sec = (unsigned long) (sec);
timeout.tv_usec = (sec - floor(sec)) * 1000000;
#include <sys/wait.h>
#include <sys/stat.h>
#include <unistd.h>
+#include <math.h> /* floor */
XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(tesh);
if (!rctx->reader_done) {
rctx->interrupted = 1;
kill(rctx->pid, SIGTERM);
- usleep(100);
+ struct timespec ts;
+ ts.tv_sec = 0;
+ ts.tv_nsec = (100e-6 - floor(100e-6)) * 1e9;
+ nanosleep (&ts, NULL);
kill(rctx->pid, SIGKILL);
}
xbt_os_mutex_release(rctx->interruption);
}
/* Give runner threads a chance to acknowledge the processes deaths */
- usleep(10000);
+ struct timespec ts;
+ ts.tv_sec = 0;
+ ts.tv_nsec = (10000e-6 - floor(10000e-6)) * 1e9;
+ nanosleep (&ts, NULL);
/* Ensure that nobody is running rctx_wait on exit */
if (fg_job)
xbt_os_mutex_acquire(rctx->interruption);
}
XBT_DEBUG("written %d chars so far", posw);
- if (got <= 0)
- usleep(100);
+ if (got <= 0){
+ struct timespec ts;
+ ts.tv_sec = 0;
+ ts.tv_nsec = (100e-6 - floor(100e-6)) * 1e9;
+ nanosleep (&ts, NULL);
+ }
}
rctx->input->data[0] = '\0';
rctx->input->used = 0;
buffout[posr] = '\0';
xbt_strbuff_append(rctx->output_got, buffout);
} else {
- usleep(100);
+ struct timespec ts;
+ ts.tv_sec = 0;
+ ts.tv_nsec = (100e-6 - floor(100e-6)) * 1e9;
+ nanosleep (&ts, NULL);
}
} while (!rctx->timeout && posr != 0);
free(buffout);
/* Wait for the child to die or the timeout to happen (or an armageddon to happen) */
while (!rctx->reader_done
&& (rctx->end_time < 0 || rctx->end_time >= now)) {
- usleep(100);
+ struct timespec ts;
+ ts.tv_sec = 0;
+ ts.tv_nsec = (100e-6 - floor(100e-6)) * 1e9;
+ nanosleep (&ts, NULL);
now = time(NULL);
}
XBT_INFO("<%s> timeouted. Kill the process.", rctx->filepos);
rctx->timeout = 1;
kill(rctx->pid, SIGTERM);
- usleep(100);
+ struct timespec ts;
+ ts.tv_sec = 0;
+ ts.tv_nsec = (100e-6 - floor(100e-6)) * 1e9;
+ nanosleep (&ts, NULL);
kill(rctx->pid, SIGKILL);
}