From abf3f1342c581a3964a463f09b1a8e719b7377a4 Mon Sep 17 00:00:00 2001 From: Sung-jae Park Date: Thu, 26 Sep 2013 11:24:52 +0900 Subject: Replace gettimeofday with clock_get_time Change-Id: I88e8eee0ab2dfd031a807aa4c4c7fb701fdd7cdf --- lib/CMakeLists.txt | 1 + lib/src/icon.c | 30 ++++++++++++++++++++++++++++-- 2 files changed, 29 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index f02c651..924ab26 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -28,6 +28,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; -- cgit v1.2.3