From 2eebbd307db214f49884f64f0cb15e6b0d6b8a49 Mon Sep 17 00:00:00 2001 From: Eladash Date: Thu, 21 Jul 2022 16:53:49 +0300 Subject: [PATCH] LV2: Minor optimization regarding signal flag --- rpcs3/Emu/Cell/SPUThread.cpp | 4 ++-- rpcs3/Emu/Cell/lv2/sys_cond.cpp | 4 ++-- rpcs3/Emu/Cell/lv2/sys_event.cpp | 4 ++-- rpcs3/Emu/Cell/lv2/sys_event_flag.cpp | 4 ++-- rpcs3/Emu/Cell/lv2/sys_lwcond.cpp | 4 ++-- rpcs3/Emu/Cell/lv2/sys_lwmutex.cpp | 4 ++-- rpcs3/Emu/Cell/lv2/sys_mutex.cpp | 4 ++-- rpcs3/Emu/Cell/lv2/sys_rwlock.cpp | 8 ++++---- rpcs3/Emu/Cell/lv2/sys_semaphore.cpp | 4 ++-- rpcs3/Emu/Cell/lv2/sys_spu.cpp | 6 ++---- rpcs3/Emu/Cell/lv2/sys_usbd.cpp | 4 ++-- 11 files changed, 24 insertions(+), 26 deletions(-) diff --git a/rpcs3/Emu/Cell/SPUThread.cpp b/rpcs3/Emu/Cell/SPUThread.cpp index 8ea60727ca..a955b34c3e 100644 --- a/rpcs3/Emu/Cell/SPUThread.cpp +++ b/rpcs3/Emu/Cell/SPUThread.cpp @@ -4860,9 +4860,9 @@ bool spu_thread::stop_and_signal(u32 code) } } - while (auto old = state.fetch_sub(cpu_flag::signal)) + while (auto old = +state) { - if (old & cpu_flag::signal) + if (old & cpu_flag::signal && state.test_and_reset(cpu_flag::signal)) { break; } diff --git a/rpcs3/Emu/Cell/lv2/sys_cond.cpp b/rpcs3/Emu/Cell/lv2/sys_cond.cpp index e190291e51..3c999257d5 100644 --- a/rpcs3/Emu/Cell/lv2/sys_cond.cpp +++ b/rpcs3/Emu/Cell/lv2/sys_cond.cpp @@ -348,9 +348,9 @@ error_code sys_cond_wait(ppu_thread& ppu, u32 cond_id, u64 timeout) return CELL_EPERM; } - while (auto state = ppu.state.fetch_sub(cpu_flag::signal)) + while (auto state = +ppu.state) { - if (state & cpu_flag::signal) + if (state & cpu_flag::signal && ppu.state.test_and_reset(cpu_flag::signal)) { break; } diff --git a/rpcs3/Emu/Cell/lv2/sys_event.cpp b/rpcs3/Emu/Cell/lv2/sys_event.cpp index ea7d324681..4c8ac60385 100644 --- a/rpcs3/Emu/Cell/lv2/sys_event.cpp +++ b/rpcs3/Emu/Cell/lv2/sys_event.cpp @@ -451,9 +451,9 @@ error_code sys_event_queue_receive(ppu_thread& ppu, u32 equeue_id, vm::ptr cause lv2_obj::sleep(ppu); lock.unlock(); - while (true) + while (auto state = +ppu.state) { - const auto state = ppu.state.fetch_sub(cpu_flag::signal); - - if (state & cpu_flag::signal) + if (state & cpu_flag::signal && ppu.state.test_and_reset(cpu_flag::signal)) { break; } diff --git a/rpcs3/Emu/Cell/lv2/sys_usbd.cpp b/rpcs3/Emu/Cell/lv2/sys_usbd.cpp index c302bfd147..5ea62ccb8e 100644 --- a/rpcs3/Emu/Cell/lv2/sys_usbd.cpp +++ b/rpcs3/Emu/Cell/lv2/sys_usbd.cpp @@ -860,9 +860,9 @@ error_code sys_usbd_receive_event(ppu_thread& ppu, u32 handle, vm::ptr arg1 usbh.sq.emplace_back(&ppu); } - while (auto state = ppu.state.fetch_sub(cpu_flag::signal)) + while (auto state = +ppu.state) { - if (state & cpu_flag::signal) + if (state & cpu_flag::signal && ppu.state.test_and_reset(cpu_flag::signal)) { sys_usbd.trace("Received event(queued): arg1=0x%x arg2=0x%x arg3=0x%x", ppu.gpr[4], ppu.gpr[5], ppu.gpr[6]); break;