From 731af51493aa76327104d3a8da564cf23f8e71d0 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Mon, 8 Jan 2007 13:00:16 +0000 Subject: [PATCH] Don't use _SC_MONOTONIC_CLOCK unless USE_CLOCK_GETTIME is defined. 2007-01-08 Matthias Clasen * 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 --- ChangeLog | 22 ++++++++++++++++++++++ gthread/gthread-impl.c | 3 ++- gthread/gthread-posix.c | 34 ++++++++++++++++++++++++++++++++-- gthread/gthread-win32.c | 13 ++++++++++++- 4 files changed, 68 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 921a38574..e0e858b96 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,25 @@ +2007-01-08 Matthias Clasen + + * 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 + + 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 * m4macros/glib-2.0.m4: Use PKG_PROG_PKG_CONFIG. (#392636, diff --git a/gthread/gthread-impl.c b/gthread/gthread-impl.c index 77615cec9..d8f26d4c5 100644 --- a/gthread/gthread-impl.c +++ b/gthread/gthread-impl.c @@ -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 diff --git a/gthread/gthread-posix.c b/gthread/gthread-posix.c index 633dcdbe9..d05165c68 100644 --- a/gthread/gthread-posix.c +++ b/gthread/gthread-posix.c @@ -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 }; diff --git a/gthread/gthread-win32.c b/gthread/gthread-win32.c index 7b85b1923..e8f1e62b9 100644 --- a/gthread/gthread-win32.c +++ b/gthread/gthread-win32.c @@ -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