From 068947e2b613d15f724c87c501949c9105cc7f7f Mon Sep 17 00:00:00 2001 From: JosJuice Date: Mon, 19 May 2025 12:08:10 +0200 Subject: [PATCH] Core: Remove IsHostThread The core no longer cares which thread is the host thread. Cleaning up Android's HostThreadLock is left for another PR, in part because the HostThreadLock in NativeConfig.cpp still serves a purpose, and in part to make any issues easier to bisect. --- Source/Android/jni/Host.h | 23 +++++------------------ Source/Core/Core/Core.cpp | 16 ---------------- Source/Core/Core/Core.h | 3 --- Source/Core/DolphinNoGUI/MainNoGUI.cpp | 2 -- Source/Core/DolphinQt/Main.cpp | 2 -- Source/Core/DolphinQt/Settings.cpp | 3 ++- Source/Core/DolphinTool/ToolMain.cpp | 2 -- Source/UnitTests/UnitTestsMain.cpp | 1 - 8 files changed, 7 insertions(+), 45 deletions(-) diff --git a/Source/Android/jni/Host.h b/Source/Android/jni/Host.h index 3a7a3048257..0183038d9a2 100644 --- a/Source/Android/jni/Host.h +++ b/Source/Android/jni/Host.h @@ -5,37 +5,24 @@ #include -#include "Core/Core.h" - // 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) { Core::DeclareAsHostThread(); } + explicit HostThreadLock() : m_lock(s_host_identity_mutex) {} - ~HostThreadLock() - { - if (m_lock.owns_lock()) - Core::UndeclareAsHostThread(); - } + ~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(); - Core::DeclareAsHostThread(); - } + void Lock() { m_lock.lock(); } - void Unlock() - { - m_lock.unlock(); - Core::UndeclareAsHostThread(); - } + void Unlock() { m_lock.unlock(); } private: static std::mutex s_host_identity_mutex; diff --git a/Source/Core/Core/Core.cpp b/Source/Core/Core/Core.cpp index ac745a22a43..6ff85a9002c 100644 --- a/Source/Core/Core/Core.cpp +++ b/Source/Core/Core/Core.cpp @@ -131,7 +131,6 @@ static Common::Event s_cpu_thread_job_finished; static thread_local bool tls_is_cpu_thread = false; static thread_local bool tls_is_gpu_thread = false; -static thread_local bool tls_is_host_thread = false; static void EmuThread(Core::System& system, std::unique_ptr boot, WindowSystemInfo wsi); @@ -212,11 +211,6 @@ bool IsGPUThread() return tls_is_gpu_thread; } -bool IsHostThread() -{ - return tls_is_host_thread; -} - bool WantsDeterminism() { return s_wants_determinism; @@ -319,16 +313,6 @@ void UndeclareAsGPUThread() tls_is_gpu_thread = false; } -void DeclareAsHostThread() -{ - tls_is_host_thread = true; -} - -void UndeclareAsHostThread() -{ - tls_is_host_thread = false; -} - // For the CPU Thread only. static void CPUSetInitialExecutionState(bool force_paused = false) { diff --git a/Source/Core/Core/Core.h b/Source/Core/Core/Core.h index 72627d0038d..462a49fa278 100644 --- a/Source/Core/Core/Core.h +++ b/Source/Core/Core/Core.h @@ -127,8 +127,6 @@ void DeclareAsCPUThread(); void UndeclareAsCPUThread(); void DeclareAsGPUThread(); void UndeclareAsGPUThread(); -void DeclareAsHostThread(); -void UndeclareAsHostThread(); std::string StopMessage(bool main_thread, std::string_view message); @@ -141,7 +139,6 @@ bool IsUninitialized(Core::System& system); bool IsCPUThread(); // this tells us whether we are the CPU thread. bool IsGPUThread(); -bool IsHostThread(); bool WantsDeterminism(); diff --git a/Source/Core/DolphinNoGUI/MainNoGUI.cpp b/Source/Core/DolphinNoGUI/MainNoGUI.cpp index 669daabec00..8abc7746c64 100644 --- a/Source/Core/DolphinNoGUI/MainNoGUI.cpp +++ b/Source/Core/DolphinNoGUI/MainNoGUI.cpp @@ -189,8 +189,6 @@ static std::unique_ptr GetPlatform(const optparse::Values& options) int main(const int argc, char* argv[]) { - Core::DeclareAsHostThread(); - const auto parser = CommandLineParse::CreateParser(CommandLineParse::ParserOptions::OmitGUIOptions); parser->add_option("-p", "--platform") diff --git a/Source/Core/DolphinQt/Main.cpp b/Source/Core/DolphinQt/Main.cpp index 49436475ae9..ce85ee1f0de 100644 --- a/Source/Core/DolphinQt/Main.cpp +++ b/Source/Core/DolphinQt/Main.cpp @@ -127,8 +127,6 @@ int main(int argc, char* argv[]) } #endif - Core::DeclareAsHostThread(); - #ifdef __APPLE__ // On macOS, a command line option matching the format "-psn_X_XXXXXX" is passed when // the application is launched for the first time. This is to set the "ProcessSerialNumber", diff --git a/Source/Core/DolphinQt/Settings.cpp b/Source/Core/DolphinQt/Settings.cpp index 2767badbec4..24bcb367b50 100644 --- a/Source/Core/DolphinQt/Settings.cpp +++ b/Source/Core/DolphinQt/Settings.cpp @@ -17,6 +17,7 @@ #include #include #include +#include #include #include "AudioCommon/AudioCommon.h" @@ -76,7 +77,7 @@ Settings::Settings() }); m_hotplug_event_hook = g_controller_interface.RegisterDevicesChangedCallback([this] { - if (Core::IsHostThread()) + if (qApp->thread() == QThread::currentThread()) { emit DevicesChanged(); } diff --git a/Source/Core/DolphinTool/ToolMain.cpp b/Source/Core/DolphinTool/ToolMain.cpp index 224ead3d7b2..058bccc7b5b 100644 --- a/Source/Core/DolphinTool/ToolMain.cpp +++ b/Source/Core/DolphinTool/ToolMain.cpp @@ -32,8 +32,6 @@ static void PrintUsage() int main(int argc, char* argv[]) { - Core::DeclareAsHostThread(); - if (argc < 2) { PrintUsage(); diff --git a/Source/UnitTests/UnitTestsMain.cpp b/Source/UnitTests/UnitTestsMain.cpp index 4eed0c60993..3edb1c19092 100644 --- a/Source/UnitTests/UnitTestsMain.cpp +++ b/Source/UnitTests/UnitTestsMain.cpp @@ -25,7 +25,6 @@ int main(int argc, char** argv) { fmt::print(stderr, "Running main() from UnitTestsMain.cpp\n"); Common::RegisterMsgAlertHandler(TestMsgHandler); - Core::DeclareAsHostThread(); ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS();