From 77320bcdb8f5bb83512cd64b54e387f6a28da7e9 Mon Sep 17 00:00:00 2001 From: Elad Ashkenazi <18193363+elad335@users.noreply.github.com> Date: Wed, 12 Jun 2024 08:42:03 +0300 Subject: [PATCH] LV2: Optimization for timeout --- rpcs3/Emu/Cell/lv2/sys_event.cpp | 6 ++++++ rpcs3/Emu/Cell/lv2/sys_event_flag.cpp | 6 ++++++ rpcs3/Emu/Cell/lv2/sys_lwmutex.cpp | 6 ++++++ rpcs3/Emu/Cell/lv2/sys_mutex.cpp | 6 ++++++ rpcs3/Emu/Cell/lv2/sys_rwlock.cpp | 6 ++++++ 5 files changed, 30 insertions(+) diff --git a/rpcs3/Emu/Cell/lv2/sys_event.cpp b/rpcs3/Emu/Cell/lv2/sys_event.cpp index 26d9ffd5902b..def5c433d23e 100644 --- a/rpcs3/Emu/Cell/lv2/sys_event.cpp +++ b/rpcs3/Emu/Cell/lv2/sys_event.cpp @@ -521,6 +521,12 @@ error_code sys_event_queue_receive(ppu_thread& ppu, u32 equeue_id, vm::ptr::load(queue->pq)) + { + // Waiters queue is empty, so the thread must have been signaled + break; + } + std::lock_guard lock(queue->mutex); if (!queue->unqueue(queue->pq, &ppu)) diff --git a/rpcs3/Emu/Cell/lv2/sys_event_flag.cpp b/rpcs3/Emu/Cell/lv2/sys_event_flag.cpp index 26f8f4468bd3..639e2db58619 100644 --- a/rpcs3/Emu/Cell/lv2/sys_event_flag.cpp +++ b/rpcs3/Emu/Cell/lv2/sys_event_flag.cpp @@ -240,6 +240,12 @@ error_code sys_event_flag_wait(ppu_thread& ppu, u32 id, u64 bitptn, u32 mode, vm continue; } + if (!atomic_storage::load(flag->sq)) + { + // Waiters queue is empty, so the thread must have been signaled + break; + } + std::lock_guard lock(flag->mutex); if (!flag->unqueue(flag->sq, &ppu)) diff --git a/rpcs3/Emu/Cell/lv2/sys_lwmutex.cpp b/rpcs3/Emu/Cell/lv2/sys_lwmutex.cpp index cfe5b7f933e2..1180edbbb268 100644 --- a/rpcs3/Emu/Cell/lv2/sys_lwmutex.cpp +++ b/rpcs3/Emu/Cell/lv2/sys_lwmutex.cpp @@ -234,6 +234,12 @@ error_code _sys_lwmutex_lock(ppu_thread& ppu, u32 lwmutex_id, u64 timeout) continue; } + if (!mutex->load_sq()) + { + // Sleep queue is empty, so the thread must have been signaled + break; + } + std::lock_guard lock(mutex->mutex); bool success = false; diff --git a/rpcs3/Emu/Cell/lv2/sys_mutex.cpp b/rpcs3/Emu/Cell/lv2/sys_mutex.cpp index 42365fe9cc79..fe9232724d9b 100644 --- a/rpcs3/Emu/Cell/lv2/sys_mutex.cpp +++ b/rpcs3/Emu/Cell/lv2/sys_mutex.cpp @@ -255,6 +255,12 @@ error_code sys_mutex_lock(ppu_thread& ppu, u32 mutex_id, u64 timeout) continue; } + if (!atomic_storage::load(mutex->control.raw().sq)) + { + // Waiters queue is empty, so the thread must have been signaled + break; + } + std::lock_guard lock(mutex->mutex); bool success = false; diff --git a/rpcs3/Emu/Cell/lv2/sys_rwlock.cpp b/rpcs3/Emu/Cell/lv2/sys_rwlock.cpp index 3a75aea91e1f..7736c6d95875 100644 --- a/rpcs3/Emu/Cell/lv2/sys_rwlock.cpp +++ b/rpcs3/Emu/Cell/lv2/sys_rwlock.cpp @@ -196,6 +196,12 @@ error_code sys_rwlock_rlock(ppu_thread& ppu, u32 rw_lock_id, u64 timeout) continue; } + if (!atomic_storage::load(rwlock->rq)) + { + // Waiters queue is empty, so the thread must have been signaled + break; + } + std::lock_guard lock(rwlock->mutex); if (!rwlock->unqueue(rwlock->rq, &ppu))