Use clock_gettime() with CLOCK_MONOTONIC which is not affected by changing system...
[platform/core/multimedia/mmsvc-core.git] / core / src / muse_core.c
index 09f2e6a..986db19 100644 (file)
@@ -24,7 +24,9 @@
 #include <sys/mman.h>
 
 #undef LOG_TAG
-#define LOG_TAG                                                "MUSED_CORE"
+#define LOG_TAG                                                                "MUSED_CORE"
+
+#define STR_TIME_FORMAT                                                "%m-%d %H:%M:%S"
 
 #define MUSE_WATCHDOG_CHECK_PERIOD                     10
 #define MUSE_WATCHDOG_CHECK_COUNT                      3
@@ -708,7 +710,7 @@ void muse_core_update_fd_state(int fd)
        if (!fd_state_table)
                fd_state_table = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, g_free);
 
-       muse_core_get_cur_time(atime);
+       muse_core_get_cur_time(NULL, atime);
        g_hash_table_insert(fd_state_table, GINT_TO_POINTER(fd), g_strdup(atime));
 
        g_mutex_unlock(&fd_state_lock);
@@ -745,18 +747,21 @@ void muse_core_destroy_fd_table(void)
        g_mutex_unlock(&fd_state_lock);
 }
 
-void muse_core_get_cur_time(char *time_buf)
+void muse_core_get_cur_time(struct timespec *time, char *time_buf)
 {
        char cur_time[MUSE_MSG_LEN];
        struct tm newtime;
-       struct timeval tv;
+       struct timespec tv;
 
-       muse_return_if_fail(time_buf);
+       muse_return_if_fail(clock_gettime(CLOCK_MONOTONIC, &tv) == 0);
 
-       gettimeofday(&tv, NULL);
-       strftime(cur_time, MUSE_MSG_LEN, "%m-%d %H:%M:%S", localtime_r(&(tv.tv_sec), &newtime));
+       if (time)
+               *time = tv;
 
-       snprintf(time_buf, MUSE_MSG_TIME_LEN, "%s.%03ld", cur_time, tv.tv_usec / 1000);
+       if (time_buf) {
+               strftime(cur_time, MUSE_MSG_LEN, STR_TIME_FORMAT, localtime_r(&(tv.tv_sec), &newtime));
+               snprintf(time_buf, MUSE_MSG_TIME_LEN, "%s.%03ld", cur_time, tv.tv_nsec);
+       }
 }
 
 void muse_core_log_process_thread_info(int pid)