summaryrefslogtreecommitdiff
path: root/src/clock.cpp
diff options
context:
space:
mode:
authorMartin Lucina <martin@lucina.net>2012-05-20 11:24:59 +0200
committerMartin Lucina <martin@lucina.net>2012-05-20 11:24:59 +0200
commit56619463ac26dc6c3e576d2fbf6b544eebeb5148 (patch)
treef23e0eed3e7d347e71e5a6b4f983692bdec2078d /src/clock.cpp
parent4016b657973bba87caf75168ba70aaa85d556487 (diff)
Imported Upstream version 2.2.0upstream
Diffstat (limited to 'src/clock.cpp')
-rw-r--r--src/clock.cpp19
1 files changed, 16 insertions, 3 deletions
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 <sys/time.h>
#endif
-#if defined HAVE_CLOCK_GETTIME
+#if defined HAVE_CLOCK_GETTIME || defined HAVE_GETHRTIME
#include <time.h>
#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.