mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-03-28 10:30:03 +01:00
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.
This commit is contained in:
parent
a48faa0aed
commit
38e7aa9855
@ -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)
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user