summaryrefslogtreecommitdiff
path: root/platform/android/src/android_thread_pool_provider.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'platform/android/src/android_thread_pool_provider.cpp')
-rw-r--r--platform/android/src/android_thread_pool_provider.cpp24
1 files changed, 24 insertions, 0 deletions
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