From 56619463ac26dc6c3e576d2fbf6b544eebeb5148 Mon Sep 17 00:00:00 2001 From: Martin Lucina Date: Sun, 20 May 2012 11:24:59 +0200 Subject: Imported Upstream version 2.2.0 --- src/clock.cpp | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'src/clock.cpp') diff --git a/src/clock.cpp b/src/clock.cpp index f1da091..96dc40c 100644 --- a/src/clock.cpp +++ b/src/clock.cpp @@ -34,7 +34,7 @@ #include #endif -#if defined HAVE_CLOCK_GETTIME +#if defined HAVE_CLOCK_GETTIME || defined HAVE_GETHRTIME #include #endif @@ -65,14 +65,27 @@ uint64_t zmq::clock_t::now_us () double ticks_div = (double) (ticksPerSecond.QuadPart / 1000000); return (uint64_t) (tick.QuadPart / ticks_div); -#elif defined HAVE_CLOCK_GETTIME +#elif defined HAVE_CLOCK_GETTIME && defined CLOCK_MONOTONIC // Use POSIX clock_gettime function to get precise monotonic time. struct timespec tv; int rc = clock_gettime (CLOCK_MONOTONIC, &tv); - errno_assert (rc == 0); + // Fix case where system has clock_gettime but CLOCK_MONOTONIC is not supported. + // Done at runtime because a ./configure check is bad for + // cross-compiling. + if( rc != 0) { + // Use POSIX gettimeofday function to get precise time. + struct timeval tv; + int rc = gettimeofday (&tv, NULL); + errno_assert (rc == 0); + return (tv.tv_sec * (uint64_t) 1000000 + tv.tv_usec); + } return (tv.tv_sec * (uint64_t) 1000000 + tv.tv_nsec / 1000); +#elif defined HAVE_GETHRTIME + + return (gethrtime () / 1000); + #else // Use POSIX gettimeofday function to get precise time. -- cgit v1.2.3