Commit faa3b899 authored by Juliusz Chroboczek's avatar Juliusz Chroboczek

Use POSIX timers if available.

This protects against clock stepping if CLOCK_MONOTONIC is implemented.
parent 41eaf51c
......@@ -6,6 +6,8 @@ DEFINES = $(PLATFORM_DEFINES)
CFLAGS = $(CDEBUGFLAGS) $(DEFINES) $(EXTRA_DEFINES)
LDLIBS = -lrt
SRCS = babel.c net.c kernel.c util.c network.c source.c neighbour.c \
route.c xroute.c message.c resend.c filter.c
......
......@@ -68,6 +68,32 @@ seqno_plus(unsigned short s, int plus)
int
gettime(struct timeval *tv)
{
#if defined(_POSIX_TIMERS) && _POSIX_TIMERS > 0 && defined(CLOCK_MONOTONIC)
static int have_posix_clocks = -1;
if(have_posix_clocks < 0) {
struct timespec ts;
int rc;
rc = clock_gettime(CLOCK_MONOTONIC, &ts);
if(rc < 0) {
have_posix_clocks = 0;
} else {
have_posix_clocks = 1;
}
}
if(have_posix_clocks) {
struct timespec ts;
int rc;
rc = clock_gettime(CLOCK_MONOTONIC, &ts);
if(rc < 0)
return rc;
tv->tv_sec = ts.tv_sec;
tv->tv_usec = ts.tv_nsec / 1000;
return rc;
}
#endif
return gettimeofday(tv, NULL);
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment