From 3206378ae6c01926f95a3a41e7384ee3758e93ef Mon Sep 17 00:00:00 2001 From: Eladash Date: Sat, 12 Sep 2020 17:16:21 +0300 Subject: [PATCH] sys_spu: Fix overexecution of cpu_return() --- rpcs3/Emu/Cell/SPUThread.cpp | 19 +++++++++++++++---- rpcs3/Emu/Cell/lv2/sys_spu.cpp | 12 +++++++++++- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/rpcs3/Emu/Cell/SPUThread.cpp b/rpcs3/Emu/Cell/SPUThread.cpp index 0dc50b260e..31eb41ebfd 100644 --- a/rpcs3/Emu/Cell/SPUThread.cpp +++ b/rpcs3/Emu/Cell/SPUThread.cpp @@ -3352,10 +3352,22 @@ bool spu_thread::stop_and_signal(u32 code) for (auto& thread : group->threads) { - if (thread && thread.get() != this) + if (thread) { - thread->state += cpu_flag::stop + cpu_flag::ret; - thread_ctrl::raw_notify(*thread); + thread->state.fetch_op([](bs_t& flags) + { + if (flags & cpu_flag::stop) + { + // In case the thread raised the ret flag itself at some point do not raise it again + return false; + } + + flags += cpu_flag::stop + cpu_flag::ret; + return true; + }); + + if (thread.get() != this) + thread_ctrl::raw_notify(*thread); } } @@ -3365,7 +3377,6 @@ bool spu_thread::stop_and_signal(u32 code) break; } - state += cpu_flag::stop + cpu_flag::ret; check_state(); return true; } diff --git a/rpcs3/Emu/Cell/lv2/sys_spu.cpp b/rpcs3/Emu/Cell/lv2/sys_spu.cpp index db8768240f..04939aecb7 100644 --- a/rpcs3/Emu/Cell/lv2/sys_spu.cpp +++ b/rpcs3/Emu/Cell/lv2/sys_spu.cpp @@ -1005,7 +1005,17 @@ error_code sys_spu_thread_group_terminate(ppu_thread& ppu, u32 id, s32 value) { if (thread) { - thread->state += cpu_flag::stop + cpu_flag::ret; + thread->state.fetch_op([](bs_t& flags) + { + if (flags & cpu_flag::stop) + { + // In case the thread raised the ret flag itself at some point do not raise it again + return false; + } + + flags += cpu_flag::stop + cpu_flag::ret; + return true; + }); } }