summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2015-01-09 15:16:16 -0800
committerElliott Hughes <enh@google.com>2015-01-09 15:16:16 -0800
commit0a18df82f4dea95b7398f8c934341fccbf04eeee (patch)
tree125c8285763ffc6d9c00b27eaed6a7aad5b317ee
parent553727e466942a10e11ee39dcb67e3f9562b471e (diff)
downloadart-0a18df82f4dea95b7398f8c934341fccbf04eeee.zip
art-0a18df82f4dea95b7398f8c934341fccbf04eeee.tar.gz
art-0a18df82f4dea95b7398f8c934341fccbf04eeee.tar.bz2
Clean up some #ifdefs.
Only the Mac doesn't have POSIX clocks. (And it still doesn't, a decade later.) glibc gained pthread_setname_np in 2.12. Only the Mac doesn't have prctl. Change-Id: I218e409f7e133736e15fb68e8a254cdc5799d667
-rw-r--r--runtime/globals.h2
-rw-r--r--runtime/native/dalvik_system_ZygoteHooks.cc4
-rw-r--r--runtime/thread.cc4
-rw-r--r--runtime/trace.cc2
-rw-r--r--runtime/utils.cc35
5 files changed, 18 insertions, 29 deletions
diff --git a/runtime/globals.h b/runtime/globals.h
index e531c3a..93026da 100644
--- a/runtime/globals.h
+++ b/runtime/globals.h
@@ -108,7 +108,7 @@ enum TraceClockSource {
kTraceClockSourceDual, // Both wall and thread CPU clocks.
};
-#if defined(HAVE_POSIX_CLOCKS)
+#if defined(__linux__)
static constexpr TraceClockSource kDefaultTraceClockSource = kTraceClockSourceDual;
#else
static constexpr TraceClockSource kDefaultTraceClockSource = kTraceClockSourceWall;
diff --git a/runtime/native/dalvik_system_ZygoteHooks.cc b/runtime/native/dalvik_system_ZygoteHooks.cc
index 5f68d60..c056adc 100644
--- a/runtime/native/dalvik_system_ZygoteHooks.cc
+++ b/runtime/native/dalvik_system_ZygoteHooks.cc
@@ -26,7 +26,7 @@
#include "ScopedUtfChars.h"
#include "thread-inl.h"
-#if defined(HAVE_PRCTL)
+#if defined(__linux__)
#include <sys/prctl.h>
#endif
@@ -35,9 +35,9 @@
namespace art {
static void EnableDebugger() {
+#if defined(__linux__)
// To let a non-privileged gdbserver attach to this
// process, we must set our dumpable flag.
-#if defined(HAVE_PRCTL)
if (prctl(PR_SET_DUMPABLE, 1, 0, 0, 0) == -1) {
PLOG(ERROR) << "prctl(PR_SET_DUMPABLE) failed for pid " << getpid();
}
diff --git a/runtime/thread.cc b/runtime/thread.cc
index d2d5be7..f6c8c3e 100644
--- a/runtime/thread.cc
+++ b/runtime/thread.cc
@@ -592,13 +592,13 @@ void Thread::GetThreadName(std::string& name) const {
}
uint64_t Thread::GetCpuMicroTime() const {
-#if defined(HAVE_POSIX_CLOCKS)
+#if defined(__linux__)
clockid_t cpu_clock_id;
pthread_getcpuclockid(tlsPtr_.pthread_self, &cpu_clock_id);
timespec now;
clock_gettime(cpu_clock_id, &now);
return static_cast<uint64_t>(now.tv_sec) * UINT64_C(1000000) + now.tv_nsec / UINT64_C(1000);
-#else
+#else // __APPLE__
UNIMPLEMENTED(WARNING);
return -1;
#endif
diff --git a/runtime/trace.cc b/runtime/trace.cc
index 29a3b09..5066e03 100644
--- a/runtime/trace.cc
+++ b/runtime/trace.cc
@@ -150,7 +150,7 @@ void Trace::FreeStackTrace(std::vector<mirror::ArtMethod*>* stack_trace) {
}
void Trace::SetDefaultClockSource(TraceClockSource clock_source) {
-#if defined(HAVE_POSIX_CLOCKS)
+#if defined(__linux__)
default_clock_source_ = clock_source;
#else
if (clock_source != kTraceClockSourceWall) {
diff --git a/runtime/utils.cc b/runtime/utils.cc
index 7234ec0..be73588 100644
--- a/runtime/utils.cc
+++ b/runtime/utils.cc
@@ -39,17 +39,10 @@
#include "scoped_thread_state_change.h"
#include "utf-inl.h"
-#if !defined(HAVE_POSIX_CLOCKS)
-#include <sys/time.h>
-#endif
-
-#if defined(HAVE_PRCTL)
-#include <sys/prctl.h>
-#endif
-
#if defined(__APPLE__)
#include "AvailabilityMacros.h" // For MAC_OS_X_VERSION_MAX_ALLOWED
#include <sys/syscall.h>
+#include <sys/time.h>
#endif
#include <backtrace/Backtrace.h> // For DumpNativeStack.
@@ -164,11 +157,11 @@ std::string GetIsoDate() {
}
uint64_t MilliTime() {
-#if defined(HAVE_POSIX_CLOCKS)
+#if defined(__linux__)
timespec now;
clock_gettime(CLOCK_MONOTONIC, &now);
return static_cast<uint64_t>(now.tv_sec) * UINT64_C(1000) + now.tv_nsec / UINT64_C(1000000);
-#else
+#else // __APPLE__
timeval now;
gettimeofday(&now, NULL);
return static_cast<uint64_t>(now.tv_sec) * UINT64_C(1000) + now.tv_usec / UINT64_C(1000);
@@ -176,11 +169,11 @@ uint64_t MilliTime() {
}
uint64_t MicroTime() {
-#if defined(HAVE_POSIX_CLOCKS)
+#if defined(__linux__)
timespec now;
clock_gettime(CLOCK_MONOTONIC, &now);
return static_cast<uint64_t>(now.tv_sec) * UINT64_C(1000000) + now.tv_nsec / UINT64_C(1000);
-#else
+#else // __APPLE__
timeval now;
gettimeofday(&now, NULL);
return static_cast<uint64_t>(now.tv_sec) * UINT64_C(1000000) + now.tv_usec;
@@ -188,11 +181,11 @@ uint64_t MicroTime() {
}
uint64_t NanoTime() {
-#if defined(HAVE_POSIX_CLOCKS)
+#if defined(__linux__)
timespec now;
clock_gettime(CLOCK_MONOTONIC, &now);
return static_cast<uint64_t>(now.tv_sec) * UINT64_C(1000000000) + now.tv_nsec;
-#else
+#else // __APPLE__
timeval now;
gettimeofday(&now, NULL);
return static_cast<uint64_t>(now.tv_sec) * UINT64_C(1000000000) + now.tv_usec * UINT64_C(1000);
@@ -200,11 +193,11 @@ uint64_t NanoTime() {
}
uint64_t ThreadCpuNanoTime() {
-#if defined(HAVE_POSIX_CLOCKS)
+#if defined(__linux__)
timespec now;
clock_gettime(CLOCK_THREAD_CPUTIME_ID, &now);
return static_cast<uint64_t>(now.tv_sec) * UINT64_C(1000000000) + now.tv_nsec;
-#else
+#else // __APPLE__
UNIMPLEMENTED(WARNING);
return -1;
#endif
@@ -1057,21 +1050,17 @@ void SetThreadName(const char* thread_name) {
} else {
s = thread_name + len - 15;
}
-#if defined(__BIONIC__)
+#if defined(__linux__)
// pthread_setname_np fails rather than truncating long strings.
- char buf[16]; // MAX_TASK_COMM_LEN=16 is hard-coded into bionic
+ char buf[16]; // MAX_TASK_COMM_LEN=16 is hard-coded in the kernel.
strncpy(buf, s, sizeof(buf)-1);
buf[sizeof(buf)-1] = '\0';
errno = pthread_setname_np(pthread_self(), buf);
if (errno != 0) {
PLOG(WARNING) << "Unable to set the name of current thread to '" << buf << "'";
}
-#elif defined(__APPLE__) && MAC_OS_X_VERSION_MAX_ALLOWED >= 1060
+#else // __APPLE__
pthread_setname_np(thread_name);
-#elif defined(HAVE_PRCTL)
- prctl(PR_SET_NAME, (unsigned long) s, 0, 0, 0); // NOLINT (unsigned long)
-#else
- UNIMPLEMENTED(WARNING) << thread_name;
#endif
}