summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2013-06-20 15:57:53 -0700
committerElliott Hughes <enh@google.com>2013-06-20 15:57:53 -0700
commit7757924895a28a43ab9f7c3931cc9f972e870ddc (patch)
treea98775de51a2e86f774efa1b1e4e18d60668c1c0
parent42602143f054ccf7ab692c8fe229dadc8fcb58e7 (diff)
downloadlibcore-7757924895a28a43ab9f7c3931cc9f972e870ddc.zip
libcore-7757924895a28a43ab9f7c3931cc9f972e870ddc.tar.gz
libcore-7757924895a28a43ab9f7c3931cc9f972e870ddc.tar.bz2
Use CLOCK_MONOTONIC_RAW for System.nanoTime.
We still need to use CLOCK_MONOTONIC on Darwin. Bug: 9511688 Change-Id: Ieb1091e24ad5cd3bab79a4de1b1494cc64eef3d4
-rw-r--r--luni/src/main/java/java/lang/System.java3
-rw-r--r--luni/src/main/native/java_lang_System.cpp6
2 files changed, 7 insertions, 2 deletions
diff --git a/luni/src/main/java/java/lang/System.java b/luni/src/main/java/java/lang/System.java
index c825118..46aed59 100644
--- a/luni/src/main/java/java/lang/System.java
+++ b/luni/src/main/java/java/lang/System.java
@@ -170,7 +170,8 @@ public final class System {
/**
* Returns the current timestamp of the most precise timer available on the
- * local system, in nanoseconds. Equivalent to Linux's {@code CLOCK_MONOTONIC}.
+ * local system, in nanoseconds. Equivalent to something like Linux's
+ * {@code CLOCK_MONOTONIC_RAW}.
*
* <p>This timestamp should only be used to measure a duration by comparing it
* against another timestamp from the same process on the same device.
diff --git a/luni/src/main/native/java_lang_System.cpp b/luni/src/main/native/java_lang_System.cpp
index 0686310..2c48309 100644
--- a/luni/src/main/native/java_lang_System.cpp
+++ b/luni/src/main/native/java_lang_System.cpp
@@ -94,7 +94,11 @@ static jlong System_currentTimeMillis(JNIEnv*, jclass) {
static jlong System_nanoTime(JNIEnv*, jclass) {
timespec now;
- clock_gettime(CLOCK_MONOTONIC, &now);
+#ifdef CLOCK_MONOTONIC_RAW
+ clock_gettime(CLOCK_MONOTONIC_RAW, &now);
+#else // Darwin, say.
+ clock_gettime(CLOCK_MONOTONIC, &now);
+#endif
return now.tv_sec * 1000000000LL + now.tv_nsec;
}