logd: liblog: logcat: switch to android_log_clockid() (2)
android_log_timestamp returns the property leading letter,
it is better to return a clockid_t with android_log_clockid()
Bug: 23668800
Change-Id: I38dee773bf3844177826b03a26b03215c79a5359
diff --git a/liblog/log_is_loggable.c b/liblog/log_is_loggable.c
index e128edb..7fc01d9 100644
--- a/liblog/log_is_loggable.c
+++ b/liblog/log_is_loggable.c
@@ -196,18 +196,18 @@
* rare, we can accept a trylock failure gracefully. Use a separate
* lock from is_loggable to keep contention down b/25563384.
*/
-static pthread_mutex_t lock_timestamp = PTHREAD_MUTEX_INITIALIZER;
+static pthread_mutex_t lock_clockid = PTHREAD_MUTEX_INITIALIZER;
-char android_log_timestamp()
+clockid_t android_log_clockid()
{
static struct cache r_time_cache = { NULL, -1, 0 };
static struct cache p_time_cache = { NULL, -1, 0 };
- char retval;
+ char c;
- if (pthread_mutex_trylock(&lock_timestamp)) {
+ if (pthread_mutex_trylock(&lock_clockid)) {
/* We are willing to accept some race in this context */
- if (!(retval = p_time_cache.c)) {
- retval = r_time_cache.c;
+ if (!(c = p_time_cache.c)) {
+ c = r_time_cache.c;
}
} else {
static uint32_t serial;
@@ -217,12 +217,12 @@
refresh_cache(&p_time_cache, "persist.logd.timestamp");
serial = current_serial;
}
- if (!(retval = p_time_cache.c)) {
- retval = r_time_cache.c;
+ if (!(c = p_time_cache.c)) {
+ c = r_time_cache.c;
}
- pthread_mutex_unlock(&lock_timestamp);
+ pthread_mutex_unlock(&lock_clockid);
}
- return tolower(retval ?: 'r');
+ return (tolower(c) == 'm') ? CLOCK_MONOTONIC : CLOCK_REALTIME;
}
diff --git a/liblog/logd_write.c b/liblog/logd_write.c
index 83c6dc2..11c6d9c 100644
--- a/liblog/logd_write.c
+++ b/liblog/logd_write.c
@@ -212,11 +212,7 @@
* };
*/
- if (android_log_timestamp() == 'm') {
- clock_gettime(CLOCK_MONOTONIC, &ts);
- } else {
- clock_gettime(CLOCK_REALTIME, &ts);
- }
+ clock_gettime(android_log_clockid(), &ts);
pmsg_header.magic = LOGGER_MAGIC;
pmsg_header.len = sizeof(pmsg_header) + sizeof(header);
diff --git a/liblog/logprint.c b/liblog/logprint.c
index ebf9786..ad52a81 100644
--- a/liblog/logprint.c
+++ b/liblog/logprint.c
@@ -203,7 +203,7 @@
p_ret->year_output = false;
p_ret->zone_output = false;
p_ret->epoch_output = false;
- p_ret->monotonic_output = android_log_timestamp() == 'm';
+ p_ret->monotonic_output = android_log_clockid() == CLOCK_MONOTONIC;
return p_ret;
}
@@ -1262,7 +1262,7 @@
nsec = entry->tv_nsec;
if (p_format->monotonic_output) {
// prevent convertMonotonic from being called if logd is monotonic
- if (android_log_timestamp() != 'm') {
+ if (android_log_clockid() != CLOCK_MONOTONIC) {
struct timespec time;
convertMonotonic(&time, entry);
now = time.tv_sec;