diff options
author | Josh Blum | 2013-06-11 13:25:45 -0700 |
---|---|---|
committer | Josh Blum | 2013-06-11 13:25:45 -0700 |
commit | d3dbd44da315d49f79ed2fe02b499e2e19037d0a (patch) | |
tree | efd7f8161cd013915a45fe18d4f1b0b7a3452e37 /include | |
parent | 04b91dfbf973404cf69a78d18e2f42906c51152d (diff) | |
download | sandhi-d3dbd44da315d49f79ed2fe02b499e2e19037d0a.tar.gz sandhi-d3dbd44da315d49f79ed2fe02b499e2e19037d0a.tar.bz2 sandhi-d3dbd44da315d49f79ed2fe02b499e2e19037d0a.zip |
gras: added backup for failing clock_gettime
Diffstat (limited to 'include')
-rw-r--r-- | include/gras/detail/chrono.hpp | 11 |
1 files changed, 9 insertions, 2 deletions
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 <ctime> +#include <sys/time.h> 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) |