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().
This commit is contained in:
Ryan Lortie 2011-08-31 15:49:35 -04:00
parent 3534ff418c
commit e48573c402
7 changed files with 6 additions and 68 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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 &&

View File

@ -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

View File

@ -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,

View File

@ -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 */