summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMika Fischer <mika.fischer@zoopnet.de>2011-12-03 13:07:30 +0100
committerMartin Sustrik <sustrik@250bpm.com>2011-12-03 13:07:30 +0100
commitaaac96d94a81fb5debe24200e20c353217baec9c (patch)
tree49d280f14a7a4c216abf281d3e4c722f79278b41 /src
parentfc17bd4117c19b027790951ac1df1a141bce9d82 (diff)
This makes clock_t insensitive to the system clock being reset by NTP or
the sysadmin, which could previously cause long hangs for instance in zmq_poll. Signed-off-by: Mika Fischer <mika.fischer@zoopnet.de>
Diffstat (limited to 'src')
-rw-r--r--src/clock.cpp12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/clock.cpp b/src/clock.cpp
index 92fc4be..4868a5f 100644
--- a/src/clock.cpp
+++ b/src/clock.cpp
@@ -34,6 +34,10 @@
#include <sys/time.h>
#endif
+#if defined HAVE_CLOCK_GETTIME
+#include <time.h>
+#endif
+
zmq::clock_t::clock_t () :
last_tsc (rdtsc ()),
last_time (now_us () / 1000)
@@ -61,6 +65,14 @@ 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
+
+ // Use POSIX clock_gettime function to get precise monotonic time.
+ struct timespec tv;
+ int rc = clock_gettime (CLOCK_MONOTONIC, &tv);
+ errno_assert (rc == 0);
+ return (tv.tv_sec * (uint64_t) 1000000 + tv.tv_nsec / 1000);
+
#else
// Use POSIX gettimeofday function to get precise time.