diff options
-rw-r--r-- | platform/android/core-files.json | 1 | ||||
-rw-r--r-- | platform/android/src/android_thread_pool_provider.cpp | 24 |
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 |