diff options
| author | JosJuice <josjuice@gmail.com> | 2025-11-16 20:59:52 +0100 |
|---|---|---|
| committer | JosJuice <josjuice@gmail.com> | 2025-11-23 15:17:20 +0100 |
| commit | 2d9f317f0491c133510bfb8e042c1d9fe022220c (patch) | |
| tree | cb7721c66297b072370097b0f9e6d913a9634972 | |
| parent | 5769fc73726fca19e21be916dfc409d5776c08fd (diff) | |
Core: Make s_cpu_thread_job_finished a local variable
Having it be static leads to a race condition if two different threads
call RunOnCPUThread with wait_for_completion set to true. (There's
currently nobody calling RunOnCPUThread from anything other than the
host thread, so this hasn't led to any consequences yet.)
| -rw-r--r-- | Source/Core/Core/Core.cpp | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/Source/Core/Core/Core.cpp b/Source/Core/Core/Core.cpp index 34a0070104..0dbfda58bd 100644 --- a/Source/Core/Core/Core.cpp +++ b/Source/Core/Core/Core.cpp @@ -27,12 +27,12 @@ #include "Common/CPUDetect.h" #include "Common/CommonPaths.h" #include "Common/CommonTypes.h" -#include "Common/Event.h" #include "Common/FPURoundMode.h" #include "Common/FatFsUtil.h" #include "Common/FileUtil.h" #include "Common/Logging/Log.h" #include "Common/MsgHandler.h" +#include "Common/OneShotEvent.h" #include "Common/ScopeGuard.h" #include "Common/StringUtil.h" #include "Common/Thread.h" @@ -127,7 +127,6 @@ struct HostJob }; static std::mutex s_host_jobs_lock; static std::queue<HostJob> s_host_jobs_queue; -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; @@ -841,6 +840,8 @@ void RunOnCPUThread(Core::System& system, Common::MoveOnlyFunction<void()> funct return; } + Common::OneShotEvent cpu_thread_job_finished; + // Pause the CPU (set it to stepping mode). const bool was_running = PauseAndLock(system); @@ -853,10 +854,9 @@ void RunOnCPUThread(Core::System& system, Common::MoveOnlyFunction<void()> funct else if (wait_for_completion) { // Queue the job function followed by triggering the event. - s_cpu_thread_job_finished.Reset(); - system.GetCPU().AddCPUThreadJob([&function] { + system.GetCPU().AddCPUThreadJob([&function, &cpu_thread_job_finished] { function(); - s_cpu_thread_job_finished.Set(); + cpu_thread_job_finished.Set(); }); } else @@ -872,7 +872,7 @@ void RunOnCPUThread(Core::System& system, Common::MoveOnlyFunction<void()> funct if (wait_for_completion) { // Periodically yield to the UI thread, so we don't deadlock. - while (!s_cpu_thread_job_finished.WaitFor(std::chrono::milliseconds(10))) + while (!cpu_thread_job_finished.WaitFor(std::chrono::milliseconds(10))) Host_YieldToUI(); } } |
