Merge pull request #8117 from weihuoya/threaded_env

android: get java env from thread local storage
This commit is contained in:
Connor McLaughlin
2019-06-08 20:42:15 +10:00
committed by GitHub
6 changed files with 33 additions and 70 deletions

View File

@ -66,8 +66,7 @@ static void ScanThreadFunc()
Common::SetCurrentThreadName("GC Adapter Scanning Thread");
NOTICE_LOG(SERIALINTERFACE, "GC Adapter scanning thread started");
JNIEnv* env;
IDCache::GetJavaVM()->AttachCurrentThread(&env, NULL);
JNIEnv* env = IDCache::GetEnvForThread();
jmethodID queryadapter_func = env->GetStaticMethodID(s_adapter_class, "QueryAdapter", "()Z");
@ -78,7 +77,6 @@ static void ScanThreadFunc()
Setup();
Common::SleepCurrentThread(1000);
}
IDCache::GetJavaVM()->DetachCurrentThread();
NOTICE_LOG(SERIALINTERFACE, "GC Adapter scanning thread stopped");
}
@ -88,8 +86,7 @@ static void Write()
Common::SetCurrentThreadName("GC Adapter Write Thread");
NOTICE_LOG(SERIALINTERFACE, "GC Adapter write thread started");
JNIEnv* env;
IDCache::GetJavaVM()->AttachCurrentThread(&env, NULL);
JNIEnv* env = IDCache::GetEnvForThread();
jmethodID output_func = env->GetStaticMethodID(s_adapter_class, "Output", "([B)I");
while (s_write_adapter_thread_running.IsSet())
@ -119,8 +116,6 @@ static void Write()
Common::YieldCPU();
}
IDCache::GetJavaVM()->DetachCurrentThread();
NOTICE_LOG(SERIALINTERFACE, "GC Adapter write thread stopped");
}
@ -130,8 +125,7 @@ static void Read()
NOTICE_LOG(SERIALINTERFACE, "GC Adapter read thread started");
bool first_read = true;
JNIEnv* env;
IDCache::GetJavaVM()->AttachCurrentThread(&env, NULL);
JNIEnv* env = IDCache::GetEnvForThread();
jfieldID payload_field = env->GetStaticFieldID(s_adapter_class, "controller_payload", "[B");
jobject payload_object = env->GetStaticObjectField(s_adapter_class, payload_field);
@ -185,8 +179,6 @@ static void Read()
s_fd = 0;
s_detected = false;
IDCache::GetJavaVM()->DetachCurrentThread();
NOTICE_LOG(SERIALINTERFACE, "GC Adapter read thread stopped");
}
@ -203,8 +195,7 @@ void Init()
s_last_init = CoreTiming::GetTicks();
}
JNIEnv* env;
IDCache::GetJavaVM()->AttachCurrentThread(&env, NULL);
JNIEnv* env = IDCache::GetEnvForThread();
jclass adapter_class = env->FindClass("org/dolphinemu/dolphinemu/utils/Java_GCAdapter");
s_adapter_class = reinterpret_cast<jclass>(env->NewGlobalRef(adapter_class));