From f0d526411cc0cd7992a160cba136a51f4aa1e9db Mon Sep 17 00:00:00 2001 From: Eladash Date: Thu, 7 May 2020 17:15:06 +0300 Subject: [PATCH] IDM: Implement idm::clear --- rpcs3/Emu/Cell/Modules/sceNpTrophy.cpp | 30 ++------------------------ rpcs3/Emu/IdManager.h | 8 +++++++ 2 files changed, 10 insertions(+), 28 deletions(-) diff --git a/rpcs3/Emu/Cell/Modules/sceNpTrophy.cpp b/rpcs3/Emu/Cell/Modules/sceNpTrophy.cpp index d5cea91bf8..97e30536ef 100644 --- a/rpcs3/Emu/Cell/Modules/sceNpTrophy.cpp +++ b/rpcs3/Emu/Cell/Modules/sceNpTrophy.cpp @@ -218,34 +218,8 @@ error_code sceNpTrophyTerm() return SCE_NP_TROPHY_ERROR_NOT_INITIALIZED; } - u32 it = 0; - u32 ids[std::max(trophy_context_t::id_count, trophy_handle_t::id_count)]; - - const auto get_handles = [&](u32 id, trophy_handle_t&) - { - ids[it++] = id; - }; - - const auto get_contexts = [&](u32 id, trophy_context_t&) - { - ids[it++] = id; - }; - - // This functionality could be implemented in idm instead - idm::select(get_handles); - - while (it) - { - idm::remove(ids[--it]); - } - - it = 0; - idm::select(get_contexts); - - while (it) - { - idm::remove(ids[--it]); - } + idm::clear(); + idm::clear(); trophy_manager->is_initialized = false; diff --git a/rpcs3/Emu/IdManager.h b/rpcs3/Emu/IdManager.h index 548daa5c75..224901d81d 100644 --- a/rpcs3/Emu/IdManager.h +++ b/rpcs3/Emu/IdManager.h @@ -323,6 +323,14 @@ public: // Remove all objects static void clear(); + // Remove all objects of a type + template + static inline void clear() + { + std::lock_guard lock(id_manager::g_mutex); + g_map[id_manager::typeinfo::get_index()].clear(); + } + // Get last ID (updated in create_id/allocate_id) static inline u32 last_id() {