change epoch time resolution to millisecond 20/181320/3
authorJeonghoon Park <jh1979.park@samsung.com>
Tue, 12 Jun 2018 05:58:54 +0000 (14:58 +0900)
committerJeonghoon Park <jh1979.park@samsung.com>
Tue, 12 Jun 2018 06:03:49 +0000 (15:03 +0900)
Change-Id: I85f5dc9a17f838b9e716769fda1db37a30ad0b27

common/common-util.c
common/common-util.h

index 56ce36e..8350099 100644 (file)
 #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)
index 959eaed..d4e8406 100644 (file)
@@ -19,7 +19,7 @@
 
 #include <time.h>
 
-#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);