diff --git a/rpcs3/Emu/Cell/Modules/cellAdec.cpp b/rpcs3/Emu/Cell/Modules/cellAdec.cpp index 8497d6bef2..68e05c91b4 100644 --- a/rpcs3/Emu/Cell/Modules/cellAdec.cpp +++ b/rpcs3/Emu/Cell/Modules/cellAdec.cpp @@ -833,7 +833,12 @@ error_code cellAdecClose(u32 handle) thread_ctrl::wait_for(1000); // hack } - idm::remove(handle); + if (!idm::remove_verify(handle, std::move(adec))) + { + // Removed by other thread beforehead + return CELL_ADEC_ERROR_ARG; + } + return CELL_OK; } diff --git a/rpcs3/Emu/Cell/Modules/cellVdec.cpp b/rpcs3/Emu/Cell/Modules/cellVdec.cpp index c25b4ce3f6..aec18bd4fc 100644 --- a/rpcs3/Emu/Cell/Modules/cellVdec.cpp +++ b/rpcs3/Emu/Cell/Modules/cellVdec.cpp @@ -693,7 +693,13 @@ error_code cellVdecClose(ppu_thread& ppu, u32 handle) } ppu_execute<&sys_interrupt_thread_disestablish>(ppu, vdec->ppu_tid); - idm::remove(handle); + + if (!idm::remove_verify(handle, std::move(vdec))) + { + // Other thread removed it beforehead + return CELL_VDEC_ERROR_ARG; + } + return CELL_OK; } diff --git a/rpcs3/Emu/Cell/Modules/sceNpSns.cpp b/rpcs3/Emu/Cell/Modules/sceNpSns.cpp index 98802be505..45922c40e0 100644 --- a/rpcs3/Emu/Cell/Modules/sceNpSns.cpp +++ b/rpcs3/Emu/Cell/Modules/sceNpSns.cpp @@ -117,15 +117,11 @@ error_code sceNpSnsFbDestroyHandle(u32 handle) return SCE_NP_SNS_ERROR_INVALID_ARGUMENT; } - const auto sfh = idm::get(handle); - - if (!sfh) + if (!idm::remove(handle)) { return SCE_NP_SNS_FB_ERROR_UNKNOWN_HANDLE; } - idm::remove(handle); - return CELL_OK; } diff --git a/rpcs3/Emu/Cell/Modules/sys_mempool.cpp b/rpcs3/Emu/Cell/Modules/sys_mempool.cpp index 1fe5cfaf0b..1b74993de1 100644 --- a/rpcs3/Emu/Cell/Modules/sys_mempool.cpp +++ b/rpcs3/Emu/Cell/Modules/sys_mempool.cpp @@ -120,7 +120,7 @@ void sys_mempool_destroy(ppu_thread& ppu, sys_mempool_t mempool) u32 mutexid = memory_pool->mutexid; sys_mutex_lock(ppu, memory_pool->mutexid, 0); - idm::remove(mempool); + idm::remove_verify(mempool, std::move(memory_pool)); sys_mutex_unlock(ppu, mutexid); sys_mutex_destroy(ppu, mutexid); sys_cond_destroy(ppu, condid); diff --git a/rpcs3/Emu/Cell/lv2/sys_interrupt.cpp b/rpcs3/Emu/Cell/lv2/sys_interrupt.cpp index fede071bd2..00d6f262eb 100644 --- a/rpcs3/Emu/Cell/lv2/sys_interrupt.cpp +++ b/rpcs3/Emu/Cell/lv2/sys_interrupt.cpp @@ -39,7 +39,7 @@ void lv2_int_serv::join() thread_ctrl::notify(*thread); (*thread)(); - idm::remove>(thread->id); + idm::remove_verify>(thread->id, thread); } error_code sys_interrupt_tag_destroy(ppu_thread& ppu, u32 intrtag) diff --git a/rpcs3/Emu/Cell/lv2/sys_spu.cpp b/rpcs3/Emu/Cell/lv2/sys_spu.cpp index 663be985ab..be133c0d54 100644 --- a/rpcs3/Emu/Cell/lv2/sys_spu.cpp +++ b/rpcs3/Emu/Cell/lv2/sys_spu.cpp @@ -1703,32 +1703,33 @@ error_code sys_raw_spu_destroy(ppu_thread& ppu, u32 id) thread->state += cpu_flag::stop; // Kernel objects which must be removed - std::unordered_map> to_remove; + std::vector, u32>> to_remove; // Clear interrupt handlers for (auto& intr : thread->int_ctrl) { - if (const auto tag = intr.tag.lock()) + if (auto tag = intr.tag.lock()) { if (auto handler = tag->handler.lock()) { // SLEEP handler->join(); - to_remove.emplace(handler.get(), 0); + to_remove.emplace_back(std::move(handler), 0); } - to_remove.emplace(tag.get(), 0); + to_remove.emplace_back(std::move(tag), 0); } } // Scan all kernel objects to determine IDs idm::select([&](u32 id, lv2_obj& obj) { - const auto found = to_remove.find(&obj); - - if (found != to_remove.end()) + for (auto& pair : to_remove) { - found->second = id; + if (pair.first.get() == std::addressof(obj)) + { + pair.second = id; + } } }); @@ -1736,12 +1737,17 @@ error_code sys_raw_spu_destroy(ppu_thread& ppu, u32 id) for (auto&& pair : to_remove) { if (pair.second >> 24 == 0xa) - idm::remove(pair.second); + idm::remove_verify(pair.second, std::move(pair.first)); if (pair.second >> 24 == 0xb) - idm::remove(pair.second); + idm::remove_verify(pair.second, std::move(pair.first)); + } + + if (!idm::remove_verify>(thread->id, std::move(thread))) + { + // Other thread destroyed beforehead + return CELL_ESRCH; } - idm::remove>(thread->id); return CELL_OK; }