From 38e7aa9855a3e18d5350733ee4177ab00cee15df Mon Sep 17 00:00:00 2001 From: Ryan Lortie Date: Mon, 1 Nov 2010 16:35:10 -0400 Subject: [PATCH] Clean up g_usleep() Remove some code that was written in 2000 to support OSes that do not have nanosleep(). nanosleep() has been specified (in POSIX-1.2001) for almost a decade now, so assume we have it (except on Windows). Remove the checks for nanosleep and nsleep from configure.ac. We're removing this code because we honestly believe that nobody will be affected. If this change negatively impacts you, please file a bug. --- configure.ac | 1 - glib/gtimer.c | 48 ++---------------------------------------------- 2 files changed, 2 insertions(+), 47 deletions(-) diff --git a/configure.ac b/configure.ac index a79575a..cd797d7 100644 --- a/configure.ac +++ b/configure.ac @@ -955,7 +955,6 @@ AC_CHECK_FUNCS(lstat strerror strsignal memmove vsnprintf stpcpy strcasecmp strn AC_CHECK_FUNCS(chown lchmod lchown fchmod fchown link statvfs statfs utimes getgrgid getpwuid) AC_CHECK_FUNCS(getmntent_r setmntent endmntent hasmntopt getmntinfo) # Check for high-resolution sleep functions -AC_CHECK_FUNCS(nanosleep nsleep) AC_CHECK_FUNCS(splice) AC_CHECK_HEADERS(crt_externs.h) diff --git a/glib/gtimer.c b/glib/gtimer.c index 18acc3f..92e3e3c 100644 --- a/glib/gtimer.c +++ b/glib/gtimer.c @@ -244,57 +244,13 @@ g_usleep (gulong microseconds) { #ifdef G_OS_WIN32 Sleep (microseconds / 1000); -#else /* !G_OS_WIN32 */ -# ifdef HAVE_NANOSLEEP +#else struct timespec request, remaining; request.tv_sec = microseconds / G_USEC_PER_SEC; request.tv_nsec = 1000 * (microseconds % G_USEC_PER_SEC); while (nanosleep (&request, &remaining) == -1 && errno == EINTR) request = remaining; -# else /* !HAVE_NANOSLEEP */ -# ifdef HAVE_NSLEEP - /* on AIX, nsleep is analogous to nanosleep */ - struct timespec request, remaining; - request.tv_sec = microseconds / G_USEC_PER_SEC; - request.tv_nsec = 1000 * (microseconds % G_USEC_PER_SEC); - while (nsleep (&request, &remaining) == -1 && errno == EINTR) - request = remaining; -# else /* !HAVE_NSLEEP */ - if (g_thread_supported ()) - { - static GStaticMutex mutex = G_STATIC_MUTEX_INIT; - static GCond* cond = NULL; - GTimeVal end_time; - - g_get_current_time (&end_time); - if (microseconds > G_MAXLONG) - { - microseconds -= G_MAXLONG; - g_time_val_add (&end_time, G_MAXLONG); - } - g_time_val_add (&end_time, microseconds); - - g_static_mutex_lock (&mutex); - - if (!cond) - cond = g_cond_new (); - - while (g_cond_timed_wait (cond, g_static_mutex_get_mutex (&mutex), - &end_time)) - /* do nothing */; - - g_static_mutex_unlock (&mutex); - } - else - { - struct timeval tv; - tv.tv_sec = microseconds / G_USEC_PER_SEC; - tv.tv_usec = microseconds % G_USEC_PER_SEC; - select(0, NULL, NULL, NULL, &tv); - } -# endif /* !HAVE_NSLEEP */ -# endif /* !HAVE_NANOSLEEP */ -#endif /* !G_OS_WIN32 */ +#endif } /** -- 2.7.4