+2006-09-01 Matthias Clasen <mclasen@redhat.com>
+
+ * configure.in: Check for CLOCK_MONOTONIC.
+
+ * glib/gtimer.c: Only use clock_gettime if we
+ have a monotonic clock.
+
2006-08-31 Matthias Clasen <mclasen@redhat.com>
* configure.in: Add missing includes to a few test
])
])
+AC_CACHE_CHECK(for monotonic clocks,
+ glib_cv_monotonic_clock,AC_TRY_RUN([
+#include <time.h>
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+ int main() {
+#if defined(_POSIX_MONOTONIC_CLOCK) && _POSIX_MONOTONIC_CLOCK >= 0 && defined(CLOCK_MONOTONIC)
+ return 0;
+#else
+ return 1;
+#endif
+ }],glib_cv_monotonic_clock=yes,glib_cv_monotonic_clock=no))
+
+GLIB_ASSERT_SET(glib_cv_monotonic_clock)
+if test "$glib_cv_monotonic_clock" = "yes"; then
+ AC_DEFINE(HAVE_MONOTONIC_CLOCK,1,[Have a monotonic clock])
+fi
+
AC_CHECK_HEADERS(crt_externs.h)
AC_CHECK_FUNCS(_NSGetEnviron)
#define G_NSEC_PER_SEC 1000000000
+#if defined(HAVE_CLOCK_GETTIME) && defined(HAVE_MONOTONIC_CLOCK)
+#define USE_CLOCK_GETTIME 1
+#endif
+
struct _GTimer
{
#ifdef G_OS_WIN32
guint64 start;
guint64 end;
-#elif HAVE_CLOCK_GETTIME
+#elif USE_CLOCK_GETTIME
struct timespec start;
struct timespec end;
gint clock;
#ifdef G_OS_WIN32
# define GETTIME(v) \
GetSystemTimeAsFileTime ((FILETIME *)&v)
-#elif HAVE_CLOCK_GETTIME
+#elif USE_CLOCK_GETTIME
# define GETTIME(v) \
clock_gettime (posix_clock, &v)
#else
gettimeofday (&v, NULL)
#endif
-#ifdef HAVE_CLOCK_GETTIME
+#ifdef USE_CLOCK_GETTIME
static gint posix_clock = 0;
static void
if (!initialized)
{
initialized = TRUE;
-#if !defined(_POSIX_MONOTONIC_CLOCK) || _POSIX_MONOTONIC_CLOCK >= 0
if (sysconf (_SC_MONOTONIC_CLOCK) >= 0)
posix_clock = CLOCK_MONOTONIC;
else
-#endif
posix_clock = CLOCK_REALTIME;
}
}
timer = g_new (GTimer, 1);
timer->active = TRUE;
-#ifdef HAVE_CLOCK_GETTIME
+#ifdef USE_CLOCK_GETTIME
init_posix_clock ();
#endif
{
#ifdef G_OS_WIN32
guint64 elapsed;
-#elif HAVE_CLOCK_GETTIME
+#elif USE_CLOCK_GETTIME
struct timespec elapsed;
#else
struct timeval elapsed;
timer->start -= elapsed;
-#elif HAVE_CLOCK_GETTIME
+#elif USE_CLOCK_GETTIME
if (timer->start.tv_nsec > timer->end.tv_nsec)
{
gdouble total;
#ifdef G_OS_WIN32
gint64 elapsed;
-#elif HAVE_CLOCK_GETTIME
+#elif USE_CLOCK_GETTIME
struct timespec elapsed;
#else
struct timeval elapsed;