Android: Remove HostThreadLock

Follow-up to 068947e. HostThreadLock no longer serves a purpose.
This commit is contained in:
JosJuice
2026-04-29 18:55:18 +02:00
parent 2b743639d8
commit c73dde2193
5 changed files with 0 additions and 72 deletions

View File

@@ -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();
}
}

View File

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

View File

@@ -1,8 +0,0 @@
// Copyright 2023 Dolphin Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include "jni/Host.h"
#include <mutex>
std::mutex HostThreadLock::s_host_identity_mutex;

View File

@@ -1,30 +0,0 @@
// Copyright 2023 Dolphin Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
#include <mutex>
// 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<std::mutex> m_lock;
};

View File

@@ -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<BootParameters>&& boot, bool riivolution)
{
HostThreadLock host_identity_guard;
if (riivolution && std::holds_alternative<BootParameters::Disc>(boot->parameters))
{
const std::string& riivolution_dir = File::GetUserPath(D_RIIVOLUTION_IDX);
@@ -603,15 +577,12 @@ static void Run(JNIEnv* env, std::unique_ptr<BootParameters>&& 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();