[android] attach/detach core thread pool's threads to JVM

This commit is contained in:
Łukasz Paczos
2019-05-21 12:45:58 +02:00
committed by Łukasz Paczos
parent 7d6255c860
commit 470b99e795
3 changed files with 12 additions and 9 deletions

View File

@@ -81,9 +81,6 @@ private:
};
RunLoop::Impl::Impl(RunLoop* runLoop_, RunLoop::Type type) : runLoop(runLoop_) {
using namespace mbgl::android;
detach = attach_jni_thread(theJVM, &env, platform::getCurrentThreadName());
loop = ALooper_prepare(0);
assert(loop);
@@ -129,9 +126,6 @@ RunLoop::Impl::~Impl() {
}
ALooper_release(loop);
using namespace mbgl::android;
detach_jni_thread(theJVM, &env, detach);
}
void RunLoop::Impl::wake() {

View File

@@ -47,9 +47,6 @@ private:
int fds[2];
JNIEnv *env = nullptr;
bool detach = false;
std::unique_ptr<Thread<Alarm>> alarm;
std::mutex mutex;

View File

@@ -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