From e83f80d4455a421a4f37e86824db484e0fc53ee2 Mon Sep 17 00:00:00 2001 From: Jerome Gaillard Date: Mon, 1 Jul 2019 11:04:51 +0100 Subject: [PATCH] Use cross-platform APIs for getting time CLOCK_THREAD_CPUTIME_ID is not defined for macOs. Bug: 117921091 Test: m libandroid_runtime on mac Change-Id: I26af05d73ecd104d3569bf286a1f56cb0e9d08ca --- core/jni/android_os_SystemClock.cpp | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/core/jni/android_os_SystemClock.cpp b/core/jni/android_os_SystemClock.cpp index 1f000d748b1fa..b1f600053b9bc 100644 --- a/core/jni/android_os_SystemClock.cpp +++ b/core/jni/android_os_SystemClock.cpp @@ -29,10 +29,8 @@ #include "jni.h" #include "core_jni_helpers.h" -#include -#include - #include +#include namespace android { @@ -49,11 +47,7 @@ static_assert(std::is_same::value, */ static jlong android_os_SystemClock_currentThreadTimeMillis() { - struct timespec tm; - - clock_gettime(CLOCK_THREAD_CPUTIME_ID, &tm); - - return tm.tv_sec * 1000LL + tm.tv_nsec / 1000000; + return nanoseconds_to_milliseconds(systemTime(SYSTEM_TIME_THREAD)); } /* @@ -61,11 +55,7 @@ static jlong android_os_SystemClock_currentThreadTimeMillis() */ static jlong android_os_SystemClock_currentThreadTimeMicro() { - struct timespec tm; - - clock_gettime(CLOCK_THREAD_CPUTIME_ID, &tm); - - return tm.tv_sec * 1000000LL + tm.tv_nsec / 1000; + return nanoseconds_to_microseconds(systemTime(SYSTEM_TIME_THREAD)); } /*