summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Andreas Gampe <agampe@google.com> 2017-01-17 13:32:52 -0800
committer Andreas Gampe <agampe@google.com> 2017-01-17 13:32:52 -0800
commitf29e04a86d336cb494f42fb4b67e1ba4d0f19e32 (patch)
tree91632b639402c7c1445099f2e0cec9ecaca39ca9
parentbea5f85f6cc574934b692ea28e61a756c1a0b102 (diff)
ART: Fix missing CLOCK_MONOTONIC on Mac
Fix the Mac build. Bug: 31455788 Test: m Change-Id: I03e927c28fe62abc1b14ea799190d00a081f33f7
-rw-r--r--runtime/openjdkjvmti/ti_timers.cc12
1 files changed, 12 insertions, 0 deletions
diff --git a/runtime/openjdkjvmti/ti_timers.cc b/runtime/openjdkjvmti/ti_timers.cc
index ce4f5518ae..24fb0419ee 100644
--- a/runtime/openjdkjvmti/ti_timers.cc
+++ b/runtime/openjdkjvmti/ti_timers.cc
@@ -33,7 +33,11 @@
#include <limits>
+#ifndef __APPLE__
#include <time.h>
+#else
+#include <sys/time.h>
+#endif
#include <unistd.h>
#include "art_jvmti.h"
@@ -70,10 +74,18 @@ jvmtiError TimerUtil::GetTime(jvmtiEnv* env ATTRIBUTE_UNUSED, jlong* nanos_ptr)
return ERR(NULL_POINTER);
}
+#ifndef __APPLE__
// Use the same implementation as System.nanoTime.
struct timespec now;
clock_gettime(CLOCK_MONOTONIC, &now);
*nanos_ptr = now.tv_sec * 1000000000LL + now.tv_nsec;
+#else
+ // No CLOCK_MONOTONIC support on older Mac OS.
+ struct timeval t;
+ t.tv_sec = t.tv_usec = 0;
+ gettimeofday(&t, NULL);
+ *nanos_ptr = static_cast<jlong>(t.tv_sec)*1000000000LL + static_cast<jlong>(t.tv_usec)*1000LL;
+#endif
return ERR(NONE);
}