2.15.6
[platform/upstream/glib.git] / gthread / gthread-posix.c
index 633dcdb..9188f84 100644 (file)
@@ -51,7 +51,7 @@
   int error = (err);                                                   \
   if (error)                                                           \
     g_error ("file %s: line %d (%s): error '%s' during '%s'",          \
-           __FILE__, __LINE__, G_GNUC_PRETTY_FUNCTION,                 \
+           __FILE__, __LINE__, G_STRFUNC,                              \
            g_strerror (error), name);                                  \
   }G_STMT_END
 
@@ -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,21 @@ g_thread_equal_posix_impl (gpointer thread1, gpointer thread2)
   return (pthread_equal (*(pthread_t*)thread1, *(pthread_t*)thread2) != 0);
 }
 
+#ifdef USE_CLOCK_GETTIME 
+static guint64
+gettime (void)
+{
+  struct timespec tv;
+
+  clock_gettime (posix_clock, &tv);
+
+  return (guint64) tv.tv_sec * G_NSEC_PER_SEC + tv.tv_nsec;
+}
+static guint64 (*g_thread_gettime_impl)(void) = gettime;
+#else
+static guint64 (*g_thread_gettime_impl)(void) = 0;
+#endif
+
 static GThreadFunctions g_thread_functions_for_glib_use_default =
 {
   g_mutex_new_posix_impl,