Use the clock_get_time instead of gettimeofday
authorSung-jae Park <nicesj.park@samsung.com>
Thu, 26 Sep 2013 02:17:07 +0000 (11:17 +0900)
committerSung-jae Park <nicesj.park@samsung.com>
Thu, 26 Sep 2013 02:17:07 +0000 (11:17 +0900)
Change-Id: I447e0656abfadc05318de9fc0a9867de5d1cadc2

CMakeLists.txt
packaging/liblivebox-service.spec
src/util.c

index b3549ac..edf5b97 100644 (file)
@@ -40,6 +40,7 @@ SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
 ADD_DEFINITIONS("-DPREFIX=\"${PREFIX}\"")
 ADD_DEFINITIONS("-DLOG_TAG=\"LIVEBOX_SERVICE\"")
 ADD_DEFINITIONS("-DNDEBUG")
+ADD_DEFINITIONS("-D_USE_ECORE_TIME_GET")
 ADD_DEFINITIONS("-DSERVICE_SOCKET=\"/opt/usr/share/live_magazine/.service.socket\"")
 
 ADD_LIBRARY(${PROJECT_NAME} SHARED
index 7383b67..22498ab 100644 (file)
@@ -1,6 +1,6 @@
 Name: liblivebox-service
 Summary: Service API for gathering installed livebox information.
-Version: 0.5.4
+Version: 0.5.5
 Release: 1
 Group: HomeTF/Livebox
 License: Flora License
index 8b3e92c..d78e3bf 100644 (file)
@@ -21,6 +21,7 @@
 #include <unistd.h>
 #include <stdlib.h>
 #include <sys/statvfs.h>
+#include <time.h>
 
 #include <dlog.h>
 
 #include "livebox-errno.h"
 
 int errno;
+static struct {
+       clockid_t type;
+} s_info = {
+       .type = CLOCK_MONOTONIC,
+};
 
 static inline char *check_native_livebox(const char *pkgname)
 {
@@ -104,11 +110,22 @@ int util_validate_livebox_package(const char *pkgname)
 
 double util_timestamp(void)
 {
-       struct timeval tv;
+       struct timespec ts;
 
-       gettimeofday(&tv, NULL);
+       do {
+               if (clock_gettime(s_info.type, &ts) == 0) {
+                       return ts.tv_sec + ts.tv_nsec / 1000000000.0f;
+               }
+
+               ErrPrint("%d: %s\n", s_info.type, strerror(errno));
+               if (s_info.type == CLOCK_MONOTONIC) {
+                       s_info.type = CLOCK_REALTIME;
+               } else if (s_info.type == CLOCK_REALTIME) {
+                       break;
+               }
+       } while (1);
 
-       return (double)tv.tv_sec + (double)tv.tv_usec / 1000000.0f;
+       return 0.0f;
 }
 
 const char *util_basename(const char *name)