# HG changeset patch # User John W. Eaton # Date 1265192305 18000 # Node ID 8cf32587d8f1cc8f0063a4ed93ff7b487fb4077b # Parent 2fcc927a87573a55d2eb9dcb7729665b101d7165 liboctave/cutils.c (octave_usleep): implement with nanosleep diff --git a/ChangeLog b/ChangeLog --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2010-02-03 John W. Eaton + + * configure.ac: Don't check for poll or usleep. + * bootstrap.conf (gnulib_modules): Include nanosleep and sleep + in the list. + 2010-02-03 John W. Eaton * configure.ac: Don't check for sigaction, sigpending, diff --git a/bootstrap.conf b/bootstrap.conf --- a/bootstrap.conf +++ b/bootstrap.conf @@ -29,6 +29,8 @@ lstat mkdir mkfifo + sleep + nanosleep pathmax readlink rename @@ -36,6 +38,7 @@ sigaction signal sigprocmask + sleep stat stdint strftime diff --git a/configure.ac b/configure.ac --- a/configure.ac +++ b/configure.ac @@ -1497,7 +1497,7 @@ realpath resolvepath rindex roundl select setgrent setlocale \ setpwent setvbuf siglongjmp \ snprintf strdup strerror strsignal tempnam tgammaf trunc umask \ - uname usleep utime vfprintf vsprintf vsnprintf waitpid \ + uname utime vfprintf vsprintf vsnprintf waitpid \ _chmod _snprintf x_utime _utime32) AC_LANG_PUSH(C++) diff --git a/src/ChangeLog b/src/ChangeLog --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,8 @@ +2010-02-03 John W. Eaton + + * cutils.c (octave_usleep): Implement using nanosleep. + (octave_sleep): Assume sleep exists. + 2010-02-03 John W. Eaton * syscalls.cc (Fcanonicalize_file_name): diff --git a/src/cutils.c b/src/cutils.c --- a/src/cutils.c +++ b/src/cutils.c @@ -24,87 +24,31 @@ #include #endif -#include #include -#include -#include +#include -#if defined (__WIN32__) && ! defined (_POSIX_VERSION) - -#include - -#else - -#include #include #include -#ifdef HAVE_POLL_H -#include -#elif HAVE_SYS_POLL_H -#include -#endif - -#endif - void octave_sleep (unsigned int seconds) { -#if defined (__WIN32__) && ! defined (_POSIX_VERSION) - Sleep (1000 * seconds); -#else sleep (seconds); -#endif } void octave_usleep (unsigned int useconds) { + struct timespec delay; + struct timespec remaining; + unsigned int sec = useconds / 1000000; unsigned int usec = useconds % 1000000; - if (sec > 0) - octave_sleep (sec); - -#if defined (__WIN32__) && ! defined (_POSIX_VERSION) - - /* Round to the nearest millisecond, with a minimum of 1 millisecond - if usleep was called with a a non-zero value. */ - - if (usec > 500) - Sleep ((usec+500)/1000); - else if (usec > 0) - Sleep (1); - else - Sleep (0); - -#elif defined (HAVE_USLEEP) - - usleep (usec); - -#elif defined (HAVE_SELECT) + delay.tv_sec = sec; + delay.tv_nsec = usec * 1000; - { - struct timeval delay; - - delay.tv_sec = 0; - delay.tv_usec = usec; - - select (0, 0, 0, 0, &delay); - } - -#elif defined (HAVE_POLL) - - { - struct pollfd pfd; - - int delay = usec / 1000; - - if (delay > 0) - poll (&pfd, 0, delay); - } - -#endif + nanosleep (&delay, &remaining); } int