[glib/wip/glib-next: 5/22] Deprecated (undocumented) g_thread_gettime
- From: Ryan Lortie <ryanl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib/wip/glib-next: 5/22] Deprecated (undocumented) g_thread_gettime
- Date: Thu, 1 Sep 2011 03:04:55 +0000 (UTC)
commit ab7e8a0582644f0bb8bb79bb49e35f1c888e8c58
Author: Ryan Lortie <desrt desrt ca>
Date: Wed Aug 31 15:49:35 2011 -0400
Deprecated (undocumented) g_thread_gettime
g_thread_gettime() is an undocumented public function pointer that
points to a function that returns the monotonic time in nanoseconds.
g_get_monotonic_time() does the same in microseconds, so it can be used
instead.
GLib had one internal user in GFileMonitor that only cared about
millisecond accuracy; it has been ported to g_get_monotonic_time().
gio/gfilemonitor.c | 2 +-
glib/gthread.c | 21 ++-------------------
glib/gthread.h | 2 ++
gthread/gthread-impl.c | 2 --
gthread/gthread-none.c | 2 --
gthread/gthread-posix.c | 29 +----------------------------
gthread/gthread-win32.c | 16 ----------------
7 files changed, 6 insertions(+), 68 deletions(-)
---
diff --git a/gio/gfilemonitor.c b/gio/gfilemonitor.c
index e4d6589..93fd23e 100644
--- a/gio/gfilemonitor.c
+++ b/gio/gfilemonitor.c
@@ -439,7 +439,7 @@ emit_in_idle (GFileMonitor *monitor,
static guint32
get_time_msecs (void)
{
- return g_thread_gettime() / (1000 * 1000);
+ return g_get_monotonic_time () / G_TIME_SPAN_MILLISECOND;
}
static guint32
diff --git a/glib/gthread.c b/glib/gthread.c
index ff56f2f..310a493 100644
--- a/glib/gthread.c
+++ b/glib/gthread.c
@@ -42,6 +42,7 @@
#include "gthread.h"
#include "gthreadprivate.h"
+#include "gmain.h"
#ifdef HAVE_UNISTD_H
#include <unistd.h>
@@ -1918,25 +1919,7 @@ g_thread_fail (void)
static guint64
gettime (void)
{
-#ifdef G_OS_WIN32
- guint64 v;
-
- /* Returns 100s of nanoseconds since start of 1601 */
- GetSystemTimeAsFileTime ((FILETIME *)&v);
-
- /* Offset to Unix epoch */
- v -= G_GINT64_CONSTANT (116444736000000000);
- /* Convert to nanoseconds */
- v *= 100;
-
- return v;
-#else
- struct timeval tv;
-
- gettimeofday (&tv, NULL);
-
- return (guint64) tv.tv_sec * G_NSEC_PER_SEC + tv.tv_usec * (G_NSEC_PER_SEC / G_USEC_PER_SEC);
-#endif
+ return g_get_monotonic_time () * 1000;
}
static gpointer
diff --git a/glib/gthread.h b/glib/gthread.h
index 1239c2d..6434d66 100644
--- a/glib/gthread.h
+++ b/glib/gthread.h
@@ -116,7 +116,9 @@ GLIB_VAR GThreadFunctions g_thread_functions_for_glib_use;
GLIB_VAR gboolean g_thread_use_default_impl;
GLIB_VAR gboolean g_threads_got_initialized;
+#ifndef G_DISABLE_DEPRECATED
GLIB_VAR guint64 (*g_thread_gettime) (void);
+#endif
/* initializes the mutex/cond/private implementation for glib, might
* only be called once, and must not be called directly or indirectly
diff --git a/gthread/gthread-impl.c b/gthread/gthread-impl.c
index 678b3b8..97a4970 100644
--- a/gthread/gthread-impl.c
+++ b/gthread/gthread-impl.c
@@ -315,8 +315,6 @@ g_thread_init (GThreadFunctions* init)
g_thread_use_default_impl = FALSE;
g_thread_functions_for_glib_use = *init;
- if (g_thread_gettime_impl)
- g_thread_gettime = g_thread_gettime_impl;
supported = (init->mutex_new &&
init->mutex_lock &&
diff --git a/gthread/gthread-none.c b/gthread/gthread-none.c
index 6fbeff1..fb4c887 100644
--- a/gthread/gthread-none.c
+++ b/gthread/gthread-none.c
@@ -34,6 +34,4 @@
static GThreadFunctions
g_thread_functions_for_glib_use_default; /* is NULLified */
-static guint64 (*g_thread_gettime_impl) (void) = NULL;
-
#define G_MUTEX_SIZE 0
diff --git a/gthread/gthread-posix.c b/gthread/gthread-posix.c
index 9188f84..5fbcf28 100644
--- a/gthread/gthread-posix.c
+++ b/gthread/gthread-posix.c
@@ -119,12 +119,7 @@ static gulong g_thread_min_stack_size = 0;
#define G_MUTEX_SIZE (sizeof (pthread_mutex_t))
-#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)
+#if defined(_SC_THREAD_STACK_MIN) || defined (HAVE_PRIORITIES)
#define HAVE_G_THREAD_IMPL_INIT
static void
g_thread_impl_init(void)
@@ -146,13 +141,6 @@ g_thread_impl_init(void)
g_thread_priority_map [priority]));
# 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 */
@@ -426,21 +414,6 @@ 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,
diff --git a/gthread/gthread-win32.c b/gthread/gthread-win32.c
index 465b205..c72d061 100644
--- a/gthread/gthread-win32.c
+++ b/gthread/gthread-win32.c
@@ -545,22 +545,6 @@ g_thread_join_win32_impl (gpointer thread)
g_free (target);
}
-static guint64
-g_thread_gettime_impl (void)
-{
- guint64 v;
-
- /* Returns 100s of nanoseconds since start of 1601 */
- GetSystemTimeAsFileTime ((FILETIME *)&v);
-
- /* Offset to Unix epoch */
- v -= G_GINT64_CONSTANT (116444736000000000);
- /* Convert to nanoseconds */
- v *= 100;
-
- return v;
-}
-
static GThreadFunctions g_thread_functions_for_glib_use_default =
{
g_mutex_new_win32_impl, /* mutex */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]