mirror of
https://github.com/zeromq/libzmq.git
synced 2025-01-19 00:46:05 +01:00
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>
This commit is contained in:
parent
fc17bd4117
commit
aaac96d94a
@ -91,6 +91,7 @@ case "${host_os}" in
|
||||
CPPFLAGS="-D_GNU_SOURCE $CPPFLAGS"
|
||||
fi
|
||||
AC_DEFINE(ZMQ_HAVE_LINUX, 1, [Have Linux OS])
|
||||
AC_CHECK_LIB(rt, clock_gettime)
|
||||
|
||||
case "${host_os}" in
|
||||
*android*)
|
||||
@ -238,7 +239,7 @@ LIBZMQ_CHECK_POLLER([CPPFLAGS="${CPPFLAGS} -D${libzmq_cv_poller_flag}"],
|
||||
# Checks for header files.
|
||||
AC_HEADER_STDC
|
||||
AC_CHECK_HEADERS(errno.h arpa/inet.h netinet/tcp.h netinet/in.h stddef.h \
|
||||
stdlib.h string.h sys/socket.h sys/time.h unistd.h limits.h)
|
||||
stdlib.h string.h sys/socket.h sys/time.h time.h unistd.h limits.h)
|
||||
|
||||
# Check if we have ifaddrs.h header file.
|
||||
AC_CHECK_HEADERS(ifaddrs.h, [AC_DEFINE(ZMQ_HAVE_IFADDRS, 1, [Have ifaddrs.h header.])])
|
||||
@ -370,7 +371,7 @@ AM_CONDITIONAL(ON_MINGW, test "x$libzmq_on_mingw32" = "xyes")
|
||||
|
||||
# Checks for library functions.
|
||||
AC_TYPE_SIGNAL
|
||||
AC_CHECK_FUNCS(perror gettimeofday memset socket getifaddrs freeifaddrs)
|
||||
AC_CHECK_FUNCS(perror gettimeofday clock_gettime memset socket getifaddrs freeifaddrs)
|
||||
AC_CHECK_HEADERS([alloca.h])
|
||||
LIBZMQ_CHECK_SOCK_CLOEXEC([AC_DEFINE(
|
||||
[ZMQ_HAVE_SOCK_CLOEXEC],
|
||||
|
@ -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.
|
||||
|
Loading…
x
Reference in New Issue
Block a user