diff --git a/Source/Android/jni/ActivityTracker.cpp b/Source/Android/jni/ActivityTracker.cpp index 20fc7df79a..35e06e422d 100644 --- a/Source/Android/jni/ActivityTracker.cpp +++ b/Source/Android/jni/ActivityTracker.cpp @@ -6,7 +6,6 @@ #include "Common/Logging/Log.h" #include "Core/AchievementManager.h" #include "UICommon/UICommon.h" -#include "jni/Host.h" extern "C" { @@ -24,7 +23,6 @@ Java_org_dolphinemu_dolphinemu_utils_ActivityTracker_setBackgroundExecutionAllow JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_utils_ActivityTracker_flushUnsavedData(JNIEnv*, jclass) { - HostThreadLock guard; UICommon::FlushUnsavedData(); } } diff --git a/Source/Android/jni/CMakeLists.txt b/Source/Android/jni/CMakeLists.txt index 4f9c015102..a15eb5c636 100644 --- a/Source/Android/jni/CMakeLists.txt +++ b/Source/Android/jni/CMakeLists.txt @@ -14,8 +14,6 @@ add_library(main SHARED GameList/GameFile.h GameList/GameFileCache.cpp GpuDriver.cpp - Host.cpp - Host.h InfinityConfig.cpp Input/Control.cpp Input/Control.h diff --git a/Source/Android/jni/Host.cpp b/Source/Android/jni/Host.cpp deleted file mode 100644 index 71647afac1..0000000000 --- a/Source/Android/jni/Host.cpp +++ /dev/null @@ -1,8 +0,0 @@ -// Copyright 2023 Dolphin Emulator Project -// SPDX-License-Identifier: GPL-2.0-or-later - -#include "jni/Host.h" - -#include - -std::mutex HostThreadLock::s_host_identity_mutex; diff --git a/Source/Android/jni/Host.h b/Source/Android/jni/Host.h deleted file mode 100644 index 0183038d9a..0000000000 --- a/Source/Android/jni/Host.h +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright 2023 Dolphin Emulator Project -// SPDX-License-Identifier: GPL-2.0-or-later - -#pragma once - -#include - -// The Core only supports using a single Host thread. -// If multiple threads want to call host functions then they need to queue -// sequentially for access. -// TODO: The above isn't true anymore, so we should get rid of this class. -struct HostThreadLock -{ - explicit HostThreadLock() : m_lock(s_host_identity_mutex) {} - - ~HostThreadLock() = default; - - HostThreadLock(const HostThreadLock& other) = delete; - HostThreadLock(HostThreadLock&& other) = delete; - HostThreadLock& operator=(const HostThreadLock& other) = delete; - HostThreadLock& operator=(HostThreadLock&& other) = delete; - - void Lock() { m_lock.lock(); } - - void Unlock() { m_lock.unlock(); } - -private: - static std::mutex s_host_identity_mutex; - std::unique_lock m_lock; -}; diff --git a/Source/Android/jni/MainAndroid.cpp b/Source/Android/jni/MainAndroid.cpp index 0e841b6d7e..3855cb4c18 100644 --- a/Source/Android/jni/MainAndroid.cpp +++ b/Source/Android/jni/MainAndroid.cpp @@ -65,7 +65,6 @@ #include "jni/AndroidCommon/AndroidCommon.h" #include "jni/AndroidCommon/IDCache.h" -#include "jni/Host.h" namespace { @@ -239,21 +238,18 @@ extern "C" { JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_UnPauseEmulation(JNIEnv*, jclass) { - HostThreadLock guard; Core::SetState(Core::System::GetInstance(), Core::State::Running); } JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_PauseEmulation( JNIEnv*, jclass, bool override_achievement_restrictions) { - HostThreadLock guard; Core::SetState(Core::System::GetInstance(), Core::State::Paused, true, override_achievement_restrictions); } JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_StopEmulation(JNIEnv*, jclass) { - HostThreadLock guard; Core::Stop(Core::System::GetInstance()); // Kick the waiting event @@ -297,7 +293,6 @@ JNIEXPORT jstring JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_GetGitRev JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_SaveScreenShot(JNIEnv*, jclass) { - HostThreadLock guard; Core::SaveScreenShot(); } @@ -310,28 +305,24 @@ JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_eglBindAPI(J JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_SaveState(JNIEnv*, jclass, jint slot) { - HostThreadLock guard; State::Save(Core::System::GetInstance(), slot); } JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_SaveStateAs(JNIEnv* env, jclass, jstring path) { - HostThreadLock guard; State::SaveAs(Core::System::GetInstance(), GetJString(env, path)); } JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_LoadState(JNIEnv*, jclass, jint slot) { - HostThreadLock guard; State::Load(Core::System::GetInstance(), slot); } JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_LoadStateAs(JNIEnv* env, jclass, jstring path) { - HostThreadLock guard; State::LoadAs(Core::System::GetInstance(), GetJString(env, path)); } @@ -360,7 +351,6 @@ Java_org_dolphinemu_dolphinemu_utils_DirectoryInitialization_SetGpuDriverDirecto JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_SetUserDirectory( JNIEnv* env, jclass, jstring jDirectory) { - HostThreadLock guard; UICommon::SetUserDirectory(GetJString(env, jDirectory)); } @@ -373,7 +363,6 @@ JNIEXPORT jstring JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_GetUserDi JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_SetCacheDirectory( JNIEnv* env, jclass, jstring jDirectory) { - HostThreadLock guard; File::SetUserPath(D_CACHE_IDX, GetJString(env, jDirectory)); } @@ -403,7 +392,6 @@ JNIEXPORT jint JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_GetMaxLogLev JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_WipeJitBlockProfilingData( JNIEnv* env, jclass native_library_class) { - HostThreadLock guard; auto& system = Core::System::GetInstance(); auto& jit_interface = system.GetJitInterface(); const Core::CPUThreadGuard cpu_guard(system); @@ -419,7 +407,6 @@ JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_WipeJitBlock JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_WriteJitBlockLogDump( JNIEnv* env, jclass native_library_class) { - HostThreadLock guard; auto& system = Core::System::GetInstance(); auto& jit_interface = system.GetJitInterface(); const Core::CPUThreadGuard cpu_guard(system); @@ -469,17 +456,11 @@ JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_SurfaceDestr { // If emulation continues running without a valid surface, we will probably crash, // so pause emulation until we get a valid surface again. EmulationFragment handles resuming. - - HostThreadLock host_identity_guard; - while (s_is_booting.IsSet()) { // Need to wait for boot to finish before we can pause - host_identity_guard.Unlock(); std::this_thread::sleep_for(std::chrono::milliseconds(1)); - host_identity_guard.Lock(); } - if (Core::GetState(Core::System::GetInstance()) == Core::State::Running) Core::SetState(Core::System::GetInstance(), Core::State::Paused); } @@ -513,28 +494,23 @@ JNIEXPORT jfloat JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_GetGameAsp JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_RefreshWiimotes(JNIEnv*, jclass) { - HostThreadLock guard; WiimoteReal::Refresh(); } JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_ReloadConfig(JNIEnv*, jclass) { - HostThreadLock guard; SConfig::GetInstance().LoadSettings(); } JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_ResetDolphinSettings(JNIEnv*, jclass) { - HostThreadLock guard; SConfig::ResetAllSettings(); UICommon::SetUserDirectory(File::GetUserPath(D_USER_IDX)); } JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_Initialize(JNIEnv*, jclass) { - HostThreadLock guard; - UICommon::CreateDirectories(); Common::RegisterMsgAlertHandler(&MsgAlert); DolphinAnalytics::AndroidSetGetValFunc(&GetAnalyticValue); @@ -570,8 +546,6 @@ static float GetRenderSurfaceScale(JNIEnv* env) static void Run(JNIEnv* env, std::unique_ptr&& boot, bool riivolution) { - HostThreadLock host_identity_guard; - if (riivolution && std::holds_alternative(boot->parameters)) { const std::string& riivolution_dir = File::GetUserPath(D_RIIVOLUTION_IDX); @@ -603,15 +577,12 @@ static void Run(JNIEnv* env, std::unique_ptr&& boot, bool riivol while (Core::IsRunning(Core::System::GetInstance())) { - host_identity_guard.Unlock(); s_update_main_frame_event.Wait(); - host_identity_guard.Lock(); Core::HostDispatchJobs(Core::System::GetInstance()); } s_game_metadata_is_valid = false; Core::Shutdown(Core::System::GetInstance()); - host_identity_guard.Unlock(); env->CallStaticVoidMethod(IDCache::GetNativeLibraryClass(), IDCache::GetFinishEmulationActivity()); @@ -652,7 +623,6 @@ JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_RunSystemMen JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_ChangeDisc(JNIEnv* env, jclass, jstring jFile) { - HostThreadLock guard; const std::string path = GetJString(env, jFile); __android_log_print(ANDROID_LOG_INFO, DOLPHIN_TAG, "Change Disc: %s", path.c_str()); auto& system = Core::System::GetInstance();