aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThiago Marcos P. Santos <thiago@mapbox.com>2016-07-15 12:18:08 +0300
committerThiago Marcos P. Santos <thiago@mapbox.com>2016-07-16 10:38:42 +0300
commitd52faadf73d8b66e39b1d5fde5d20d3cdce12d8c (patch)
tree1de1d1e72ba5408b2019c4fe0690304eb5d140de
parent538814d7bd42b851c6ca2d6ab97066b30ee2c748 (diff)
[android] Set thread name properly
-rw-r--r--platform/android/platform.gyp2
-rw-r--r--platform/android/src/run_loop.cpp3
-rw-r--r--platform/android/src/thread.cpp37
3 files changed, 40 insertions, 2 deletions
diff --git a/platform/android/platform.gyp b/platform/android/platform.gyp
index c5b81c974..171fc0b51 100644
--- a/platform/android/platform.gyp
+++ b/platform/android/platform.gyp
@@ -31,7 +31,7 @@
'src/log_android.cpp',
'src/http_file_source.cpp',
'src/asset_file_source.cpp',
- '../default/thread.cpp',
+ 'src/thread.cpp',
'../default/string_stdlib.cpp',
'../default/image.cpp',
'../default/png_reader.cpp',
diff --git a/platform/android/src/run_loop.cpp b/platform/android/src/run_loop.cpp
index 007ea2919..1e5fc9b4b 100644
--- a/platform/android/src/run_loop.cpp
+++ b/platform/android/src/run_loop.cpp
@@ -1,5 +1,6 @@
#include "run_loop_impl.hpp"
+#include <mbgl/platform/platform.hpp>
#include <mbgl/util/thread_context.hpp>
#include <mbgl/util/thread_local.hpp>
#include <mbgl/util/timer.hpp>
@@ -75,7 +76,7 @@ private:
RunLoop::Impl::Impl(RunLoop* runLoop_, RunLoop::Type type) : runLoop(runLoop_) {
using namespace mbgl::android;
- detach = attach_jni_thread(theJVM, &env, "");
+ detach = attach_jni_thread(theJVM, &env, platform::getCurrentThreadName());
loop = ALooper_prepare(0);
assert(loop);
diff --git a/platform/android/src/thread.cpp b/platform/android/src/thread.cpp
new file mode 100644
index 000000000..77f981586
--- /dev/null
+++ b/platform/android/src/thread.cpp
@@ -0,0 +1,37 @@
+#include <mbgl/platform/log.hpp>
+#include <mbgl/platform/platform.hpp>
+
+#include <sys/prctl.h>
+#include <sys/resource.h>
+
+// Implementation based on Chromium's platform_thread_android.cc.
+
+namespace mbgl {
+namespace platform {
+
+std::string getCurrentThreadName() {
+ char name[32] = "unknown";
+
+ if (prctl(PR_GET_NAME, name) == -1) {
+ Log::Warning(Event::General, "Couldn't get thread name");
+ }
+
+ return name;
+}
+
+void setCurrentThreadName(const std::string& name) {
+ if (prctl(PR_SET_NAME, name.c_str()) == -1) {
+ Log::Warning(Event::General, "Couldn't set thread name");
+ }
+}
+
+void makeThreadLowPriority() {
+ // ANDROID_PRIORITY_LOWEST = 19
+ //
+ // Supposedly would set the priority for the whole process, but
+ // on Linux/Android it only sets for the current thread.
+ setpriority(PRIO_PROCESS, 0, 19);
+}
+
+} // namespace platform
+} // namespace mbgl