summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorŁukasz Paczos <lukas.paczos@gmail.com>2019-05-10 17:01:52 +0200
committerŁukasz Paczos <lukas.paczos@gmail.com>2019-05-10 17:38:23 +0200
commit49dd3eb35288e54f6fe9c808b1ba4679c3bd0dbf (patch)
tree6971199cf624040c64ca5d6bc52aaf5e8cb1b40b
parent8a44ed2603e020b7147a872bc6cf0b6223acc64f (diff)
downloadqtlocation-mapboxgl-upstream/lp-thread-detaching-14048-copy.tar.gz
[android] overwrite default ThreadLifecycleupstream/lp-thread-detaching-14048-copy
-rw-r--r--platform/android/core-files.json1
-rw-r--r--platform/android/src/android_thread_pool_provider.cpp24
2 files changed, 25 insertions, 0 deletions
diff --git a/platform/android/core-files.json b/platform/android/core-files.json
index ba56695bdd..e35c7b5ffd 100644
--- a/platform/android/core-files.json
+++ b/platform/android/core-files.json
@@ -85,6 +85,7 @@
"platform/android/src/thread.cpp",
"platform/android/src/timer.cpp",
"platform/android/src/unaccent.cpp",
+ "platform/android/src/android_thread_pool_provider.cpp",
"platform/default/src/mbgl/gl/headless_backend.cpp",
"platform/default/src/mbgl/gl/headless_frontend.cpp",
"platform/default/src/mbgl/map/map_snapshotter.cpp",
diff --git a/platform/android/src/android_thread_pool_provider.cpp b/platform/android/src/android_thread_pool_provider.cpp
new file mode 100644
index 0000000000..a136bb9681
--- /dev/null
+++ b/platform/android/src/android_thread_pool_provider.cpp
@@ -0,0 +1,24 @@
+#include <mbgl/util/thread_pool_provider.hpp>
+#include <mbgl/util/platform.hpp>
+#include <cassert>
+#include "jni.hpp"
+
+namespace mbgl {
+std::shared_ptr<ThreadPool> getThreadPool() {
+ ThreadLifecycle lifecycle = {
+ [] {
+ using namespace android;
+ JNIEnv* env = nullptr;
+ attach_jni_thread(theJVM, &env, platform::getCurrentThreadName());
+ return env;
+ },
+ [](ThreadLifecycle::ThreadData threadData_) {
+ using namespace android;
+ assert(threadData_);
+ auto* env = static_cast<JNIEnv*>(threadData_);
+ detach_jni_thread(theJVM, &env, true);
+ }
+ };
+ return std::make_shared<ThreadPool>(4, lifecycle);
+}
+} // namespace mbgl \ No newline at end of file