From 1420e44bb1ecd7496230d6315d9e17597ffbc42c Mon Sep 17 00:00:00 2001 From: Tamas TEVESZ Date: Wed, 29 Sep 2010 02:52:19 +0200 Subject: [PATCH] WINGs: Modernize wusleep() - Change the wusleep abomination to be a simple wrapper around nanosleep (man says it's been POSIX for almost a decade) - Remove autoconf tests that became unnecessary along the way Signed-off-by: Tamas TEVESZ --- WINGs/WINGs/WUtil.h | 2 +- WINGs/usleep.c | 59 +++++++++++++++------------------------------ configure.ac | 6 ++--- 3 files changed, 22 insertions(+), 45 deletions(-) diff --git a/WINGs/WINGs/WUtil.h b/WINGs/WINGs/WUtil.h index 19785d3d..cc1a3210 100644 --- a/WINGs/WINGs/WUtil.h +++ b/WINGs/WINGs/WUtil.h @@ -248,7 +248,7 @@ WMRange wmkrange(int start, int count); /* ---[ WINGs/usleep.c ]-------------------------------------------------- */ -void wusleep(unsigned int microsec); +void wusleep(unsigned int usec); /* ---[ WINGs/handlers.c ]------------------------------------------------ */ diff --git a/WINGs/usleep.c b/WINGs/usleep.c index 792b9475..acf0583d 100644 --- a/WINGs/usleep.c +++ b/WINGs/usleep.c @@ -1,46 +1,25 @@ +#include +#include + #include "wconfig.h" -#ifdef HAVE_SYS_TIME_H -# include -#endif - -#ifdef HAVE_SYS_TYPES_H -# include -#endif - -#include -#include - -#if defined(HAVE_SELECT) - -#ifdef HAVE_SYS_SELECT_H -# include -#endif - -void wusleep(unsigned int microsecs) +void wusleep(unsigned int usec) { - struct timeval tv; - fd_set rd, wr, ex; - FD_ZERO(&rd); - FD_ZERO(&wr); - FD_ZERO(&ex); - tv.tv_sec = microsecs / 1000000u; - tv.tv_usec = microsecs % 1000000u; - select(1, &rd, &wr, &ex, &tv); + struct timespec tm; + + /* An arbitrary limit of 10 minutes -- in WM, if + * somethings wants to sleep anything even close to + * this, it's most likely an error. + */ + if (usec > 600000000) + return; + + tm.tv_sec = usec / 1000000; + tm.tv_nsec = usec % 1000000; + + while (nanosleep(&tm, &tm) == -1 && errno == EINTR) + ; + } -#else /* not HAVE_SELECT */ - -# ifdef HAVE_POLL - -void wusleep(unsigned int microsecs) -{ - poll((struct poll *)0, (size_t) 0, microsecs / 1000); -} - -# else /* ! HAVE_POLL */ - -oops ! -# endif /* !HAVE_POLL */ -#endif /* !HAVE_SELECT */ diff --git a/configure.ac b/configure.ac index 0363c4a0..2caa212d 100644 --- a/configure.ac +++ b/configure.ac @@ -230,10 +230,8 @@ dnl Checks for header files. dnl ======================= AC_HEADER_SYS_WAIT AC_HEADER_TIME -AC_CHECK_HEADERS(fcntl.h limits.h sys/ioctl.h sys/time.h sys/types.h \ - libintl.h sys/select.h poll.h malloc.h ctype.h string.h \ - strings.h) - +AC_CHECK_HEADERS(fcntl.h limits.h sys/ioctl.h libintl.h poll.h malloc.h ctype.h \ + string.h strings.h) dnl Checks for typedefs, structures, and compiler characteristics.