From a107a86f958dabe0484657b49fedcd5759c1f351 Mon Sep 17 00:00:00 2001 From: Sung-jae Park Date: Thu, 26 Sep 2013 11:23:30 +0900 Subject: [PATCH] Replace gettimeofday with clock_get_time Change-Id: I14b08f44189049ce68880c4a804c618f6c933377 --- lib/CMakeLists.txt | 1 + lib/src/icon.c | 30 ++++++++++++++++++++++++++++-- packaging/libshortcut.spec | 2 +- 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index f088671..04f8ce0 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -29,6 +29,7 @@ SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}") ADD_DEFINITIONS("-DPREFIX=\"${PREFIX}\"") ADD_DEFINITIONS("-DLOG_TAG=\"SHORTCUT\"") +ADD_DEFINITIONS("-D_USE_ECORE_TIME_GET") ADD_LIBRARY(${PROJECT_NAME} SHARED src/main.c diff --git a/lib/src/icon.c b/lib/src/icon.c index 0fb83da..06877fc 100644 --- a/lib/src/icon.c +++ b/lib/src/icon.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #include @@ -44,7 +45,6 @@ #define CREATED 0x00BEEF00 #define DESTROYED 0x00DEAD00 - static struct info { int fd; int (*init_cb)(int status, void *data); @@ -54,6 +54,9 @@ static struct info { const char *utility_socket; struct dlist *pending_list; +#if defined(_USE_ECORE_TIME_GET) + clockid_t type; +#endif } s_info = { .fd = -1, .init_cb = NULL, @@ -62,6 +65,9 @@ static struct info { .utility_socket = "/tmp/.utility.service", .pending_list = NULL, +#if defined(_USE_ECORE_TIME_GET) + .type = CLOCK_MONOTONIC, +#endif }; @@ -672,7 +678,6 @@ EAPI int shortcut_icon_request_send(struct shortcut_icon *handle, int size_type, struct packet *packet; struct request_item *item; char *filename; - struct timeval tv; int len; if (!handle || handle->state != CREATED) { @@ -695,6 +700,26 @@ EAPI int shortcut_icon_request_send(struct shortcut_icon *handle, int size_type, return -ENOMEM; } +#if defined(_USE_ECORE_TIME_GET) + struct timespec ts; + double tv; + do { + if (clock_gettime(s_info.type, &ts) == 0) { + tv = ts.tv_sec + ts.tv_nsec / 1000000000.0f; + break; + } + + 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) { + tv = rand(); + break; + } + } while (1); + ret = snprintf(filename, len, "%s.%lf.desc", outfile, tv); +#else + struct timeval tv; if (gettimeofday(&tv, NULL) != 0) { ErrPrint("gettimeofday: %s\n", strerror(errno)); tv.tv_sec = rand(); @@ -702,6 +727,7 @@ EAPI int shortcut_icon_request_send(struct shortcut_icon *handle, int size_type, } ret = snprintf(filename, len, "%s.%lu.%lu.desc", outfile, tv.tv_sec, tv.tv_usec); +#endif if (ret < 0) { ErrPrint("snprintf: %s\n", strerror(errno)); goto out; diff --git a/packaging/libshortcut.spec b/packaging/libshortcut.spec index e5619c6..ac4dc02 100644 --- a/packaging/libshortcut.spec +++ b/packaging/libshortcut.spec @@ -1,6 +1,6 @@ Name: libshortcut Summary: Shortcut add feature supporting library -Version: 0.6.7 +Version: 0.6.8 Release: 0 Group: HomeTF/Framework License: Apache License -- 2.7.4