Mercurial > hg > octave-avbm
changeset 10253:8cf32587d8f1
liboctave/cutils.c (octave_usleep): implement with nanosleep
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 03 Feb 2010 05:18:25 -0500 |
parents | 2fcc927a8757 |
children | 874510cea891 |
files | ChangeLog bootstrap.conf configure.ac src/ChangeLog src/cutils.c |
diffstat | 5 files changed, 22 insertions(+), 64 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2010-02-03 John W. Eaton <jwe@octave.org> + + * 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 <jwe@octave.org> * configure.ac: Don't check for sigaction, sigpending,
--- 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
--- 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++)
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,8 @@ +2010-02-03 John W. Eaton <jwe@octave.org> + + * cutils.c (octave_usleep): Implement using nanosleep. + (octave_sleep): Assume sleep exists. + 2010-02-03 John W. Eaton <jwe@octave.org> * syscalls.cc (Fcanonicalize_file_name):
--- a/src/cutils.c +++ b/src/cutils.c @@ -24,87 +24,31 @@ #include <config.h> #endif -#include <stdarg.h> #include <stdio.h> -#include <stdlib.h> -#include <string.h> +#include <time.h> -#if defined (__WIN32__) && ! defined (_POSIX_VERSION) - -#include <windows.h> - -#else - -#include <sys/time.h> #include <sys/types.h> #include <unistd.h> -#ifdef HAVE_POLL_H -#include <poll.h> -#elif HAVE_SYS_POLL_H -#include <sys/poll.h> -#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