From 675fde69aa183d932d43ef46fa5ecf69d872c92b Mon Sep 17 00:00:00 2001 From: Eladash Date: Sun, 31 May 2020 14:21:51 +0300 Subject: [PATCH] Avoid copying std::shared_ptr in sys_semaphore --- rpcs3/Emu/Cell/lv2/sys_semaphore.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/rpcs3/Emu/Cell/lv2/sys_semaphore.cpp b/rpcs3/Emu/Cell/lv2/sys_semaphore.cpp index 93621241eb..7f78106584 100644 --- a/rpcs3/Emu/Cell/lv2/sys_semaphore.cpp +++ b/rpcs3/Emu/Cell/lv2/sys_semaphore.cpp @@ -229,15 +229,18 @@ error_code sys_semaphore_post(ppu_thread& ppu, u32 sem_id, s32 count) { std::lock_guard lock(sem->mutex); - const s32 val = sem->val.fetch_op([=](s32& val) + const auto [val, ok] = sem->val.fetch_op([&](s32& val) { - if (val + s64{count} <= sem->max) + if (count + 0u <= sem->max + 0u - val) { val += count; + return true; } + + return false; }); - if (val + s64{count} > sem->max) + if (!ok) { return not_an_error(CELL_EBUSY); }