summaryrefslogtreecommitdiff
path: root/platform/android/src/thread.cpp
diff options
context:
space:
mode:
authorŁukasz Paczos <lukas.paczos@gmail.com>2019-05-21 12:45:58 +0200
committerŁukasz Paczos <lukasz.paczos@mapbox.com>2019-05-22 15:52:55 +0200
commit470b99e7957b44fb929fe95d0a8b58c41583e7f6 (patch)
treecedc7870a2c2ae347bfb523cc47e5d14d21a3686 /platform/android/src/thread.cpp
parent7d6255c8605bd18a7c7d90de19346392a51c90b7 (diff)
downloadqtlocation-mapboxgl-470b99e7957b44fb929fe95d0a8b58c41583e7f6.tar.gz
[android] attach/detach core thread pool's threads to JVM
Diffstat (limited to 'platform/android/src/thread.cpp')
-rw-r--r--platform/android/src/thread.cpp12
1 files changed, 12 insertions, 0 deletions
diff --git a/platform/android/src/thread.cpp b/platform/android/src/thread.cpp
index 721c63a531..cd0a72306e 100644
--- a/platform/android/src/thread.cpp
+++ b/platform/android/src/thread.cpp
@@ -5,11 +5,17 @@
#include <sys/prctl.h>
#include <sys/resource.h>
+#include <cassert>
+#include "jni.hpp"
+
// Implementation based on Chromium's platform_thread_android.cc.
namespace mbgl {
namespace platform {
+thread_local static JNIEnv* env;
+thread_local static bool detach;
+
std::string getCurrentThreadName() {
char name[32] = "unknown";
@@ -35,9 +41,15 @@ void makeThreadLowPriority() {
}
void attachThread() {
+ using namespace android;
+ assert(env == nullptr);
+ detach = attach_jni_thread(theJVM, &env, platform::getCurrentThreadName());
}
void detachThread() {
+ using namespace android;
+ assert(env);
+ detach_jni_thread(theJVM, &env, detach);
}
} // namespace platform