From 51e23e0ab73016482d4eba73208bb63226f7493a Mon Sep 17 00:00:00 2001 From: Wayne Davison Date: Sun, 5 Apr 2020 09:22:00 -0700 Subject: [PATCH] Use nanosleep if it is available. Fixes bug #14328. --- configure.ac | 2 +- util2.c | 14 +++++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/configure.ac b/configure.ac index 4f68e98a..0756242f 100644 --- a/configure.ac +++ b/configure.ac @@ -599,7 +599,7 @@ AC_CHECK_FUNCS(waitpid wait4 getcwd strdup chown chmod lchmod mknod mkfifo \ setlocale setmode open64 lseek64 mkstemp64 mtrace va_copy __va_copy \ seteuid strerror putenv iconv_open locale_charset nl_langinfo getxattr \ extattr_get_link sigaction sigprocmask setattrlist getgrouplist \ - initgroups utimensat posix_fallocate attropen setvbuf usleep) + initgroups utimensat posix_fallocate attropen setvbuf nanosleep usleep) dnl cygwin iconv.h defines iconv_open as libiconv_open if test x"$ac_cv_func_iconv_open" != x"yes"; then diff --git a/util2.c b/util2.c index 619c92eb..b46677c0 100644 --- a/util2.c +++ b/util2.c @@ -28,13 +28,21 @@ /** * Sleep for a specified number of milliseconds. * - * Always returns TRUE. (In the future it might return FALSE if - * interrupted.) + * Always returns True. **/ int msleep(int t) { -#ifdef HAVE_USLEEP +#ifdef HAVE_NANOSLEEP + struct timespec ts; + + ts.tv_sec = t / 1000; + ts.tv_nsec = (t % 1000) * 1000000L; + + while (nanosleep(&ts, &ts) < 0 && errno == EINTR) {} + +#elif defined HAVE_USLEEP usleep(t*1000); + #else int tdiff = 0; struct timeval tval, t1, t2; -- 2.47.2