From d3dbd44da315d49f79ed2fe02b499e2e19037d0a Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Tue, 11 Jun 2013 13:25:45 -0700 Subject: gras: added backup for failing clock_gettime --- include/gras/detail/chrono.hpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/gras/detail/chrono.hpp b/include/gras/detail/chrono.hpp index bd247e5..9fe317a 100644 --- a/include/gras/detail/chrono.hpp +++ b/include/gras/detail/chrono.hpp @@ -29,6 +29,7 @@ namespace gras #else #include +#include namespace gras { @@ -36,8 +37,14 @@ namespace gras GRAS_FORCE_INLINE time_ticks_t time_now(void) { struct timespec ts; - clock_gettime(CLOCK_MONOTONIC, &ts); - return ts.tv_sec*1000000000UL + ts.tv_nsec; + if (clock_gettime(CLOCK_MONOTONIC, &ts) == 0) + return ts.tv_sec*1000000000UL + ts.tv_nsec; + + struct timeval tv; + if (gettimeofday(&tv, NULL) == 0) + return tv.tv_sec*1000000000UL + tv.tv_usec*1000UL; + + return 0; } GRAS_FORCE_INLINE time_ticks_t time_tps(void) -- cgit