Don't use _SC_MONOTONIC_CLOCK unless USE_CLOCK_GETTIME is defined.

2007-01-08  Matthias Clasen  <mclasen@redhat.com>

        * gthread/gthread-posix.c (g_thread_impl_init): Don't
        use _SC_MONOTONIC_CLOCK unless USE_CLOCK_GETTIME is
        defined.  (#394150)



svn path=/branches/glib-2-12/; revision=5231
This commit is contained in:
Matthias Clasen
2007-01-08 13:00:16 +00:00
committed by Matthias Clasen
parent 61927a5f64
commit 731af51493
4 changed files with 68 additions and 4 deletions

View File

@@ -1,3 +1,25 @@
2007-01-08 Matthias Clasen <mclasen@redhat.com>
* gthread/gthread-posix.c (g_thread_impl_init): Don't
use _SC_MONOTONIC_CLOCK unless USE_CLOCK_GETTIME is
defined. (#394150)
2007-01-07 Matthias Clasen <mclasen@redhat.com>
Don't link glib against libpthread. (#393812)
* configure.in: Link gthread against librt, not glib itself.
* glib/gthread.h:
* glib/gthread.c: Add a new thread function, gettime.
* glib/gtimer.c: Use gettime instead of directly working with
the various system interfaces.
* gthread/gthread-impl.c:
* gthread/gthread-posix.c:
* gthread/gthread-win32.c: Implement gettime.
2007-01-07 Matthias Clasen <mclasen@redhat.com>
* m4macros/glib-2.0.m4: Use PKG_PROG_PKG_CONFIG. (#392636,

View File

@@ -332,7 +332,8 @@ g_thread_init (GThreadFunctions* init)
init->thread_join &&
init->thread_exit &&
init->thread_set_priority &&
init->thread_self);
init->thread_self &&
init->gettime);
/* if somebody is calling g_thread_init (), it means that he wants to
* have thread support, so check this

View File

@@ -119,7 +119,12 @@ static gulong g_thread_min_stack_size = 0;
#define G_MUTEX_SIZE (sizeof (pthread_mutex_t))
#if defined(_SC_THREAD_STACK_MIN) || defined (HAVE_PRIORITIES)
#if defined(HAVE_CLOCK_GETTIME) && defined(HAVE_MONOTONIC_CLOCK)
#define USE_CLOCK_GETTIME 1
static gint posix_clock = 0;
#endif
#if defined(_SC_THREAD_STACK_MIN) || defined (HAVE_PRIORITIES) || defined (USE_CLOCK_GETTIME)
#define HAVE_G_THREAD_IMPL_INIT
static void
g_thread_impl_init(void)
@@ -142,6 +147,12 @@ g_thread_impl_init(void)
# endif
#endif /* HAVE_PRIORITIES */
#ifdef USE_CLOCK_GETTIME
if (sysconf (_SC_MONOTONIC_CLOCK) >= 0)
posix_clock = CLOCK_MONOTONIC;
else
posix_clock = CLOCK_REALTIME;
#endif
}
#endif /* _SC_THREAD_STACK_MIN || HAVE_PRIORITIES */
@@ -415,6 +426,24 @@ g_thread_equal_posix_impl (gpointer thread1, gpointer thread2)
return (pthread_equal (*(pthread_t*)thread1, *(pthread_t*)thread2) != 0);
}
static guint64
g_gettime_posix_impl (void)
{
#ifdef USE_CLOCK_GETTIME
struct timespec tv;
clock_gettime (posix_clock, &tv);
return tv.tv_sec * 1e9 + tv.tv_nsec;
#else
struct timeval tv;
gettimeofday (&tv, NULL);
return tv.tv_sec * 1e9 + tv.tv_usec * 1000;
#endif
}
static GThreadFunctions g_thread_functions_for_glib_use_default =
{
g_mutex_new_posix_impl,
@@ -437,5 +466,6 @@ static GThreadFunctions g_thread_functions_for_glib_use_default =
g_thread_exit_posix_impl,
g_thread_set_priority_posix_impl,
g_thread_self_posix_impl,
g_thread_equal_posix_impl
g_thread_equal_posix_impl,
g_gettime_posix_impl
};

View File

@@ -545,6 +545,16 @@ g_thread_join_win32_impl (gpointer thread)
g_free (target);
}
static guint64
g_gettime_win32_impl (void)
{
guint64 v;
GetSystemTimeAsFileTime ((FILETIME *)&v);
return v;
}
static GThreadFunctions g_thread_functions_for_glib_use_default =
{
g_mutex_new_win32_impl, /* mutex */
@@ -567,7 +577,8 @@ static GThreadFunctions g_thread_functions_for_glib_use_default =
g_thread_exit_win32_impl,
g_thread_set_priority_win32_impl,
g_thread_self_win32_impl,
NULL /* no equal function necessary */
NULL, /* no equal function necessary */
g_gettime_win32_impl
};
#define HAVE_G_THREAD_IMPL_INIT