From 9fd1d1d236b48d2918bcb0bb715155cf1d009622 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 3a7a304825..0183038d9a 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 63878e4bef..427925792d 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); @@ -215,11 +214,6 @@ bool IsGPUThread() return tls_is_gpu_thread; } -bool IsHostThread() -{ - return tls_is_host_thread; -} - bool WantsDeterminism() { return s_wants_determinism; @@ -334,16 +328,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 72cf5d9ba1..00fb8da583 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 81051adb78..9487bb1fac 100644 --- a/Source/Core/DolphinNoGUI/MainNoGUI.cpp +++ b/Source/Core/DolphinNoGUI/MainNoGUI.cpp @@ -199,8 +199,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 535c2370e4..dff9a82c0d 100644 --- a/Source/Core/DolphinQt/Main.cpp +++ b/Source/Core/DolphinQt/Main.cpp @@ -125,8 +125,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 993f53b621..1004562242 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_callback_handle = 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 224ead3d7b..058bccc7b5 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 4eed0c6099..3edb1c1909 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();