summaryrefslogtreecommitdiff
path: root/utils/loc_log.cpp
diff options
context:
space:
mode:
authorBaili Feng <bailif@codeaurora.org>2018-01-11 15:25:27 +0800
committerBaili Feng <bailif@codeaurora.org>2018-01-11 19:44:11 +0800
commit52f5cfe9d7d9a6c4a2c7f047bd01cd85ed25d2d9 (patch)
treedd09447429adacf36a85d23339d9b39e696be8cd /utils/loc_log.cpp
parentc98dcaa84072a901167d0083fc3fef6b98077052 (diff)
downloadgps-52f5cfe9d7d9a6c4a2c7f047bd01cd85ed25d2d9.tar.gz
init condition with attr CLOCK_MONOTONIC
Use MONOTONIC time to keep consistence with pthread_cond_timedwait. CRs-fixed: 2169171 Change-Id: I25f308ff343e2f9f938275a572fbff35b659e782
Diffstat (limited to 'utils/loc_log.cpp')
-rw-r--r--utils/loc_log.cpp13
1 files changed, 7 insertions, 6 deletions
diff --git a/utils/loc_log.cpp b/utils/loc_log.cpp
index ca78f15..9fad9e6 100644
--- a/utils/loc_log.cpp
+++ b/utils/loc_log.cpp
@@ -165,15 +165,15 @@ RETURN VALUE
===========================================================================*/
char *loc_get_time(char *time_string, size_t buf_size)
{
- struct timespec now; /* sec and usec */
+ struct timeval now; /* sec and usec */
struct tm now_tm; /* broken-down time */
char hms_string[80]; /* HH:MM:SS */
- clock_gettime(CLOCK_MONOTONIC, &now);
+ gettimeofday(&now, NULL);
localtime_r(&now.tv_sec, &now_tm);
strftime(hms_string, sizeof hms_string, "%H:%M:%S", &now_tm);
- snprintf(time_string, buf_size, "%s.%03d", hms_string, (int) (now.tv_nsec / 1000000LL));
+ snprintf(time_string, buf_size, "%s.%03d", hms_string, (int) (now.tv_usec / 1000));
return time_string;
}
@@ -224,13 +224,14 @@ SIDE EFFECTS
===========================================================================*/
char * get_timestamp(char *str, unsigned long buf_size)
{
- struct timespec tv;
+ struct timeval tv;
+ struct timezone tz;
int hh, mm, ss;
- clock_gettime(CLOCK_MONOTONIC, &tv);
+ gettimeofday(&tv, &tz);
hh = tv.tv_sec/3600%24;
mm = (tv.tv_sec%3600)/60;
ss = tv.tv_sec%60;
- snprintf(str, buf_size, "%02d:%02d:%02d.%06ld", hh, mm, ss, tv.tv_nsec / 1000);
+ snprintf(str, buf_size, "%02d:%02d:%02d.%06ld", hh, mm, ss, tv.tv_usec);
return str;
}