Complete making the kernel thread-safe #2 + Fix Shared Memory Implementation

This commit makes the kernel completely thread-safe and fixes an issue that caused libNX games to not work due to an error with KSharedMemory. In addition, implement GroupMutex to allow the kernel threads to run in parallel but still allow them to not overlap with the JNI thread.
This commit is contained in:
◱ PixelyIon
2020-01-11 10:22:25 +05:30
committed by ◱ PixelyIon
parent de6d8d8f48
commit 65018aedbc
39 changed files with 547 additions and 932 deletions

View File

@ -5,21 +5,21 @@ thread_local JNIEnv *env;
namespace skyline {
JvmManager::JvmManager(JNIEnv *environ, jobject instance) : instance(instance), instanceClass(reinterpret_cast<jclass>(environ->NewGlobalRef(environ->GetObjectClass(instance)))) {
env = environ;
if(env->GetJavaVM(&vm) < 0)
if (env->GetJavaVM(&vm) < 0)
throw exception("Cannot get JavaVM from environment");
}
void JvmManager::AttachThread() {
if(!env)
if (!env)
vm->AttachCurrentThread(&env, nullptr);
}
void JvmManager::DetachThread() {
if(env)
if (env)
vm->DetachCurrentThread();
}
JNIEnv* JvmManager::GetEnv() {
JNIEnv *JvmManager::GetEnv() {
return env;
}
@ -31,7 +31,7 @@ namespace skyline {
return env->IsSameObject(env->GetObjectField(instance, env->GetFieldID(instanceClass, key, signature)), nullptr);
}
bool JvmManager::CheckNull(jobject& object) {
bool JvmManager::CheckNull(jobject &object) {
return env->IsSameObject(object, nullptr);
}
}