diff options
author | Łukasz Paczos <lukas.paczos@gmail.com> | 2019-04-12 13:15:06 +0200 |
---|---|---|
committer | Łukasz Paczos <lukas.paczos@gmail.com> | 2019-04-12 13:15:06 +0200 |
commit | 74ad75d7abdf1b55a6bf2c735b3596bd523a665e (patch) | |
tree | 139e48349187a342b90f2fd222dd1306860442dd /platform/android | |
parent | a039c7915e077a92c74a247a37d935ebee1b83a6 (diff) | |
download | qtlocation-mapboxgl-74ad75d7abdf1b55a6bf2c735b3596bd523a665e.tar.gz |
jni thread re-attachingupstream/lp-jni-reattaching-test
Diffstat (limited to 'platform/android')
-rw-r--r-- | platform/android/src/attach_env.cpp | 4 | ||||
-rw-r--r-- | platform/android/src/style/sources/geojson_source.cpp | 15 | ||||
-rw-r--r-- | platform/android/src/style/sources/geojson_source.hpp | 4 |
3 files changed, 15 insertions, 8 deletions
diff --git a/platform/android/src/attach_env.cpp b/platform/android/src/attach_env.cpp index 6da075ee3e..0dc8069284 100644 --- a/platform/android/src/attach_env.cpp +++ b/platform/android/src/attach_env.cpp @@ -1,3 +1,5 @@ +#include <android/log.h> +#include <mbgl/util/platform.hpp> #include "attach_env.hpp" #include "jni.hpp" @@ -10,8 +12,10 @@ UniqueEnv AttachEnv() { switch (err) { case JNI_OK: + __android_log_write(ANDROID_LOG_ERROR, "JNI_THREAD", ("is attached: " + mbgl::platform::getCurrentThreadName()).c_str()); return UniqueEnv(env, JNIEnvDeleter(*theJVM, false)); case JNI_EDETACHED: + __android_log_write(ANDROID_LOG_ERROR, "JNI_THREAD", ("is detached: " + mbgl::platform::getCurrentThreadName()).c_str()); return UniqueEnv(jni::AttachCurrentThread(*theJVM).release(), JNIEnvDeleter(*theJVM, true)); default: throw std::system_error(err, jni::ErrorCategory()); diff --git a/platform/android/src/style/sources/geojson_source.cpp b/platform/android/src/style/sources/geojson_source.cpp index bf4f95e4c4..7fccc36a9f 100644 --- a/platform/android/src/style/sources/geojson_source.cpp +++ b/platform/android/src/style/sources/geojson_source.cpp @@ -17,6 +17,7 @@ #include "../conversion/url_or_tileset.hpp" #include <string> +#include <mbgl/util/shared_thread_pool.hpp> // GeoJSONSource uses a "coalescing" model for high frequency asynchronous data update calls, // which in practice means, that any update that started processing is going to finish @@ -47,14 +48,16 @@ namespace android { : Source(env, std::make_unique<mbgl::style::GeoJSONSource>( jni::Make<std::string>(env, sourceId), convertGeoJSONOptions(env, options))) - , converter(std::make_unique<util::Thread<FeatureConverter>>("GeoJSONSource")) { + , threadPool(sharedThreadPool()) + , converter(std::make_unique<Actor<FeatureConverter>>(*threadPool)) { } GeoJSONSource::GeoJSONSource(jni::JNIEnv& env, mbgl::style::Source& coreSource, AndroidRendererFrontend& frontend) : Source(env, coreSource, createJavaPeer(env), frontend) - , converter(std::make_unique<util::Thread<FeatureConverter>>("GeoJSONSource")) { + , threadPool(sharedThreadPool()) + , converter(std::make_unique<Actor<FeatureConverter>>(*threadPool)) { } GeoJSONSource::~GeoJSONSource() = default; @@ -64,7 +67,7 @@ namespace android { std::shared_ptr<std::string> json = std::make_shared<std::string>(jni::Make<std::string>(env, jString)); Update::Converter converterFn = [this, json](ActorRef<Callback> _callback) { - converter->actor().invoke(&FeatureConverter::convertJson, json, _callback); + converter->self().invoke(&FeatureConverter::convertJson, json, _callback); }; setAsync(converterFn); @@ -167,7 +170,7 @@ namespace android { auto object = std::make_shared<decltype(global)>(std::move(global)); Update::Converter converterFn = [this, object](ActorRef<Callback> _callback) { - converter->actor().invoke(&FeatureConverter::convertObject<JNIType>, object, _callback); + converter->self().invoke(&FeatureConverter::convertObject<JNIType>, object, _callback); }; setAsync(converterFn); @@ -178,12 +181,12 @@ namespace android { std::move(converterFn), std::make_unique<Actor<Callback>>( *Scheduler::GetCurrent(), - [this](GeoJSON geoJSON) { + [this](GeoJSON /*geoJSON*/) { // conversion from Java features to core ones finished android::UniqueEnv _env = android::AttachEnv(); // Update the core source - source.as<mbgl::style::GeoJSONSource>()->GeoJSONSource::setGeoJSON(geoJSON); +// source.as<mbgl::style::GeoJSONSource>()->GeoJSONSource::setGeoJSON(geoJSON); // if there is an awaiting update, execute it, otherwise, release resources if (awaitingUpdate) { diff --git a/platform/android/src/style/sources/geojson_source.hpp b/platform/android/src/style/sources/geojson_source.hpp index fcfbf06f38..e737e41924 100644 --- a/platform/android/src/style/sources/geojson_source.hpp +++ b/platform/android/src/style/sources/geojson_source.hpp @@ -7,7 +7,6 @@ #include "../../geojson/feature_collection.hpp" #include "../../android_renderer_frontend.hpp" #include <jni/jni.hpp> -#include <mbgl/util/thread.hpp> namespace mbgl { namespace android { @@ -60,7 +59,8 @@ private: jni::Local<jni::Object<Source>> createJavaPeer(jni::JNIEnv&); std::unique_ptr<Update> awaitingUpdate; std::unique_ptr<Update> update; - std::unique_ptr<util::Thread<FeatureConverter>> converter; + std::shared_ptr<ThreadPool> threadPool; + std::unique_ptr<Actor<FeatureConverter>> converter; template <class JNIType> void setCollectionAsync(jni::JNIEnv&, const jni::Object<JNIType>&); |