summaryrefslogtreecommitdiff
path: root/Source/Core
diff options
context:
space:
mode:
authorJosJuice <josjuice@gmail.com>2023-06-06 13:50:20 +0200
committerGitHub <noreply@github.com>2023-06-06 13:50:20 +0200
commit2d56daf1bb62dfdf3db98e541071b17065b3c849 (patch)
tree9ee2f57e149df1a500a62c7a1660e7587f278cb1 /Source/Core
parent83b4af86b6defab21bc695dc9d6e876ac67b345d (diff)
parentb3c9f49cbedd03673a490cbeb7f886a3663e3bb8 (diff)
Merge pull request #11873 from AdmiralCurtiss/pause-and-lock-host
Core: Assert that only the Host thread may call PauseAndLock().
Diffstat (limited to 'Source/Core')
-rw-r--r--Source/Core/Core/Core.cpp18
-rw-r--r--Source/Core/Core/Core.h3
-rw-r--r--Source/Core/DolphinNoGUI/MainNoGUI.cpp2
-rw-r--r--Source/Core/DolphinQt/Host.cpp10
-rw-r--r--Source/Core/DolphinQt/Main.cpp2
-rw-r--r--Source/Core/DolphinQt/Settings.cpp2
-rw-r--r--Source/Core/DolphinTool/ToolMain.cpp3
7 files changed, 28 insertions, 12 deletions
diff --git a/Source/Core/Core/Core.cpp b/Source/Core/Core/Core.cpp
index 514863b5f8..c73fe46fd9 100644
--- a/Source/Core/Core/Core.cpp
+++ b/Source/Core/Core/Core.cpp
@@ -130,6 +130,7 @@ 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(std::unique_ptr<BootParameters> boot, WindowSystemInfo wsi);
@@ -224,6 +225,11 @@ bool IsGPUThread()
return tls_is_gpu_thread;
}
+bool IsHostThread()
+{
+ return tls_is_host_thread;
+}
+
bool WantsDeterminism()
{
return s_wants_determinism;
@@ -338,6 +344,16 @@ 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)
{
@@ -777,6 +793,8 @@ void SaveScreenShot(std::string_view name)
static bool PauseAndLock(Core::System& system, bool do_lock, bool unpause_on_unlock)
{
// WARNING: PauseAndLock is not fully threadsafe so is only valid on the Host Thread
+ ASSERT(IsHostThread());
+
if (!IsRunningAndStarted())
return true;
diff --git a/Source/Core/Core/Core.h b/Source/Core/Core/Core.h
index e237e25711..0ff8c32b5c 100644
--- a/Source/Core/Core/Core.h
+++ b/Source/Core/Core/Core.h
@@ -132,6 +132,8 @@ void DeclareAsCPUThread();
void UndeclareAsCPUThread();
void DeclareAsGPUThread();
void UndeclareAsGPUThread();
+void DeclareAsHostThread();
+void UndeclareAsHostThread();
std::string StopMessage(bool main_thread, std::string_view message);
@@ -140,6 +142,7 @@ bool IsRunningAndStarted(); // is running and the CPU loop has been entere
bool IsRunningInCurrentThread(); // this tells us whether we are running in the CPU thread.
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 887181acb2..ff69e6bf7a 100644
--- a/Source/Core/DolphinNoGUI/MainNoGUI.cpp
+++ b/Source/Core/DolphinNoGUI/MainNoGUI.cpp
@@ -185,6 +185,8 @@ static std::unique_ptr<Platform> GetPlatform(const optparse::Values& options)
int main(int argc, char* argv[])
{
+ Core::DeclareAsHostThread();
+
auto parser = CommandLineParse::CreateParser(CommandLineParse::ParserOptions::OmitGUIOptions);
parser->add_option("-p", "--platform")
.action("store")
diff --git a/Source/Core/DolphinQt/Host.cpp b/Source/Core/DolphinQt/Host.cpp
index 036dc2cffa..6a4939b106 100644
--- a/Source/Core/DolphinQt/Host.cpp
+++ b/Source/Core/DolphinQt/Host.cpp
@@ -59,16 +59,6 @@ Host* Host::GetInstance()
return s_instance;
}
-void Host::DeclareAsHostThread()
-{
- tls_is_host_thread = true;
-}
-
-bool Host::IsHostThread()
-{
- return tls_is_host_thread;
-}
-
void Host::SetRenderHandle(void* handle)
{
m_render_to_main = Config::Get(Config::MAIN_RENDER_TO_MAIN);
diff --git a/Source/Core/DolphinQt/Main.cpp b/Source/Core/DolphinQt/Main.cpp
index 8fa1afff19..1c658e8d62 100644
--- a/Source/Core/DolphinQt/Main.cpp
+++ b/Source/Core/DolphinQt/Main.cpp
@@ -123,7 +123,7 @@ int main(int argc, char* argv[])
}
#endif
- Host::GetInstance()->DeclareAsHostThread();
+ Core::DeclareAsHostThread();
#ifdef __APPLE__
// On macOS, a command line option matching the format "-psn_X_XXXXXX" is passed when
diff --git a/Source/Core/DolphinQt/Settings.cpp b/Source/Core/DolphinQt/Settings.cpp
index d915f4e916..c6a06336e2 100644
--- a/Source/Core/DolphinQt/Settings.cpp
+++ b/Source/Core/DolphinQt/Settings.cpp
@@ -71,7 +71,7 @@ Settings::Settings()
});
m_hotplug_callback_handle = g_controller_interface.RegisterDevicesChangedCallback([this] {
- if (Host::GetInstance()->IsHostThread())
+ if (Core::IsHostThread())
{
emit DevicesChanged();
}
diff --git a/Source/Core/DolphinTool/ToolMain.cpp b/Source/Core/DolphinTool/ToolMain.cpp
index 59613a17f6..263104a976 100644
--- a/Source/Core/DolphinTool/ToolMain.cpp
+++ b/Source/Core/DolphinTool/ToolMain.cpp
@@ -8,6 +8,7 @@
#include <vector>
#include "Common/Version.h"
+#include "Core/Core.h"
#include "DolphinTool/Command.h"
#include "DolphinTool/ConvertCommand.h"
#include "DolphinTool/HeaderCommand.h"
@@ -27,6 +28,8 @@ static int PrintUsage(int code)
int main(int argc, char* argv[])
{
+ Core::DeclareAsHostThread();
+
if (argc < 2)
return PrintUsage(1);