From: Jeonghoon Park Date: Tue, 12 Jun 2018 05:58:54 +0000 (+0900) Subject: change epoch time resolution to millisecond X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F20%2F181320%2F3;p=apps%2Fnative%2Ftizen-things-daemon.git change epoch time resolution to millisecond Change-Id: I85f5dc9a17f838b9e716769fda1db37a30ad0b27 --- diff --git a/common/common-util.c b/common/common-util.c index 56ce36e..8350099 100644 --- a/common/common-util.c +++ b/common/common-util.c @@ -24,6 +24,16 @@ #define CLOCK_MONOTONIC_COARSE CLOCK_MONOTONIC #endif +static inline long long __timespec_to_ms(struct timespec ts) +{ + return (((long long) ts.tv_sec) * 1000) + (ts.tv_nsec / 1000000); +} + +static inline long long __timespec_to_ns(struct timespec ts) +{ + return (((long long) ts.tv_sec) * 1000000) + (ts.tv_nsec / 1000); +} + long long common_get_monotonic_time(void) { struct timespec ts; @@ -34,7 +44,7 @@ long long common_get_monotonic_time(void) if (result != 0) return 0; - return (((unsigned long long) ts.tv_sec) * 1000000) + (ts.tv_nsec / 1000); + return __timespec_to_ns(ts); } long long common_get_monotonic_coarse_time(void) @@ -47,29 +57,33 @@ long long common_get_monotonic_coarse_time(void) if (result != 0) return 0; - return (((unsigned long long) ts.tv_sec) * 1000000) + (ts.tv_nsec / 1000); + return __timespec_to_ns(ts); } long long common_get_epoch_time(void) { - long long int ret_time = 0; - struct timespec time_s; + struct timespec ts; + int result; - if (0 == clock_gettime(CLOCK_REALTIME, &time_s)) - ret_time = time_s.tv_sec; + result = clock_gettime(CLOCK_REALTIME, &ts); - return ret_time; + if (result != 0) + return 0; + + return __timespec_to_ms(ts); } long long common_get_epoch_coarse_time(void) { - long long int ret_time = 0; - struct timespec time_s; + struct timespec ts; + int result; + + result = clock_gettime(CLOCK_REALTIME_COARSE, &ts); - if (0 == clock_gettime(CLOCK_REALTIME_COARSE, &time_s)) - ret_time = time_s.tv_sec; + if (result != 0) + return 0; - return ret_time; + return __timespec_to_ms(ts); } int common_get_epoch_timespec(struct timespec *tp) diff --git a/common/common-util.h b/common/common-util.h index 959eaed..d4e8406 100644 --- a/common/common-util.h +++ b/common/common-util.h @@ -19,7 +19,7 @@ #include -#define EPOCH_TIME_REF 1526515200 /* 2018-05-17 GMT */ +#define EPOCH_TIME_REF 1526515200000 /* 2018-05-17 GMT */ long long common_get_monotonic_time(void); long long common_get_monotonic_coarse_time(void);