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); }