From 2cacaa2da4b4d0c489a06528bd02368d0bf8ba84 Mon Sep 17 00:00:00 2001 From: Elad <18193363+elad335@users.noreply.github.com> Date: Tue, 14 Jul 2026 12:15:23 +0300 Subject: [PATCH] IDM: Optimize IDs for concurrency --- rpcs3/Emu/IdManager.h | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/rpcs3/Emu/IdManager.h b/rpcs3/Emu/IdManager.h index e8dde8fb8d..a626995ce9 100644 --- a/rpcs3/Emu/IdManager.h +++ b/rpcs3/Emu/IdManager.h @@ -802,9 +802,16 @@ public: { stx::shared_ptr ptr; { + const u32 index = get_index(id); + + if (index >= id_manager::id_traits::count) + { + return false; + } + std::lock_guard lock(id_manager::g_mutex); - if (const auto found = find_id(id); found.first) + if (const auto found = find_index(index, id); found.first) { ptr = found.first->exchange(null_ptr); found.second->clear(); @@ -834,9 +841,16 @@ public: { stx::shared_ptr ptr; { + const u32 index = get_index(id); + + if (index >= id_manager::id_traits::count) + { + return false; + } + [[maybe_unused]] std::conditional_t, const shared_mutex&> lock(id_manager::g_mutex); - if (const auto found = find_id(id); found.first && found.first->is_equal(sptr)) + if (const auto found = find_index(index, id); found.first && found.first->is_equal(sptr)) { ptr = found.first->exchange(null_ptr); found.second->clear(); @@ -866,9 +880,16 @@ public: { stx::shared_ptr ptr; { + const u32 index = get_index(id); + + if (index >= id_manager::id_traits::count) + { + return ptr; + } + [[maybe_unused]] std::conditional_t, const shared_mutex&> lock(id_manager::g_mutex); - if (const auto found = find_id(id); found.first) + if (const auto found = find_index(index, id); found.first) { ptr = static_cast>(found.first->exchange(null_ptr)); found.second->clear();