From e7c5d8925fd691a0f316ef14468d469ce0546e9d Mon Sep 17 00:00:00 2001 From: "[CST] Focus" Date: Mon, 5 Mar 2012 19:59:39 +0400 Subject: [PATCH] driver/abstime.c: add time_monotonic_us --- src/driver/abstime.c | 12 ++++++++++++ src/driver/abstime.h | 3 +++ 2 files changed, 15 insertions(+) diff --git a/src/driver/abstime.c b/src/driver/abstime.c index c2af8d4f7..af7c1c7fc 100644 --- a/src/driver/abstime.c +++ b/src/driver/abstime.c @@ -1,3 +1,4 @@ +#include #include /* for perror */ #include @@ -27,3 +28,14 @@ time_t time_monotonic(void) time comparisons if the uptime is low, so add 7 days */ return t.tv_sec + 604800; } + +uint64_t time_monotonic_us(void) +{ + struct timespec t; + if (clock_gettime(CLOCK_MONOTONIC, &t)) + { + perror("time_monotonic_us clock_gettime"); + return -1; + } + return ((int64_t)t.tv_sec + (uint64_t)604800) * (uint64_t) 1000000 + (uint64_t) t.tv_nsec / (uint64_t)1000; +} diff --git a/src/driver/abstime.h b/src/driver/abstime.h index bbd000993..b530755b6 100644 --- a/src/driver/abstime.h +++ b/src/driver/abstime.h @@ -1,3 +1,5 @@ +#include + #ifndef _ABS_TIME_H_ #define _ABS_TIME_H_ #ifdef __cplusplus @@ -6,6 +8,7 @@ extern "C" #endif extern time_t time_monotonic_ms(void); extern time_t time_monotonic(void); +uint64_t time_monotonic_us(void); #ifdef __cplusplus } #endif