From c681395fb2584157fcc3d90a9b18f608faba9c4b Mon Sep 17 00:00:00 2001 From: Eladash Date: Fri, 14 May 2021 17:55:07 +0300 Subject: [PATCH] sys_interrupt: weak_ptr -> shared_ptr --- rpcs3/Emu/Cell/SPUThread.cpp | 4 ++-- rpcs3/Emu/Cell/SPUThread.h | 2 +- rpcs3/Emu/Cell/lv2/sys_interrupt.cpp | 12 +++++++++--- rpcs3/Emu/Cell/lv2/sys_interrupt.h | 2 +- rpcs3/Emu/Cell/lv2/sys_spu.cpp | 10 +++++----- rpcs3/rpcs3qt/kernel_explorer.cpp | 4 ++-- 6 files changed, 20 insertions(+), 14 deletions(-) diff --git a/rpcs3/Emu/Cell/SPUThread.cpp b/rpcs3/Emu/Cell/SPUThread.cpp index 21f8b1ac7f..602782717e 100644 --- a/rpcs3/Emu/Cell/SPUThread.cpp +++ b/rpcs3/Emu/Cell/SPUThread.cpp @@ -1160,9 +1160,9 @@ void spu_int_ctrl_t::set(u64 ints) { std::shared_lock rlock(id_manager::g_mutex); - if (const auto tag_ptr = tag.lock()) + if (tag && tag->exists) { - if (auto handler = tag_ptr->handler.lock()) + if (auto handler = tag->handler; handler && handler->exists) { rlock.unlock(); handler->exec(); diff --git a/rpcs3/Emu/Cell/SPUThread.h b/rpcs3/Emu/Cell/SPUThread.h index d8924207fa..139f6b97ca 100644 --- a/rpcs3/Emu/Cell/SPUThread.h +++ b/rpcs3/Emu/Cell/SPUThread.h @@ -474,7 +474,7 @@ struct spu_int_ctrl_t atomic_t mask; atomic_t stat; - std::weak_ptr tag; + std::shared_ptr tag; void set(u64 ints); diff --git a/rpcs3/Emu/Cell/lv2/sys_interrupt.cpp b/rpcs3/Emu/Cell/lv2/sys_interrupt.cpp index f5103e6290..121dd22d30 100644 --- a/rpcs3/Emu/Cell/lv2/sys_interrupt.cpp +++ b/rpcs3/Emu/Cell/lv2/sys_interrupt.cpp @@ -12,6 +12,7 @@ LOG_CHANNEL(sys_interrupt); lv2_int_tag::lv2_int_tag() noexcept : id(idm::last_id()) { + exists.release(1); } lv2_int_serv::lv2_int_serv(const std::shared_ptr>& thread, u64 arg1, u64 arg2) noexcept @@ -20,6 +21,7 @@ lv2_int_serv::lv2_int_serv(const std::shared_ptr>& thre , arg1(arg1) , arg2(arg2) { + exists.release(1); } void lv2_int_serv::exec() const @@ -61,11 +63,12 @@ error_code sys_interrupt_tag_destroy(ppu_thread& ppu, u32 intrtag) const auto tag = idm::withdraw(intrtag, [](lv2_int_tag& tag) -> CellError { - if (!tag.handler.expired()) + if (tag.handler && tag.handler->exists) { return CELL_EBUSY; } + tag.exists.release(0); return {}; }); @@ -120,7 +123,7 @@ error_code _sys_interrupt_thread_establish(ppu_thread& ppu, vm::ptr ih, u32 } // It's unclear if multiple handlers can be established on single interrupt tag - if (!tag->handler.expired()) + if (tag->handler && tag->handler->exists) { error = CELL_ESTAT; return result; @@ -148,7 +151,10 @@ error_code _sys_interrupt_thread_disestablish(ppu_thread& ppu, u32 ih, vm::ptr(ih); + const auto handler = idm::withdraw(ih, [](lv2_obj& obj) + { + obj.exists.release(0); + }); if (!handler) { diff --git a/rpcs3/Emu/Cell/lv2/sys_interrupt.h b/rpcs3/Emu/Cell/lv2/sys_interrupt.h index cc9be17dc1..f28af0b6e5 100644 --- a/rpcs3/Emu/Cell/lv2/sys_interrupt.h +++ b/rpcs3/Emu/Cell/lv2/sys_interrupt.h @@ -11,7 +11,7 @@ struct lv2_int_tag final : lv2_obj static const u32 id_base = 0x0a000000; const u32 id; - std::weak_ptr handler; + std::shared_ptr handler; lv2_int_tag() noexcept; }; diff --git a/rpcs3/Emu/Cell/lv2/sys_spu.cpp b/rpcs3/Emu/Cell/lv2/sys_spu.cpp index f36cbc8b6a..2355346f23 100644 --- a/rpcs3/Emu/Cell/lv2/sys_spu.cpp +++ b/rpcs3/Emu/Cell/lv2/sys_spu.cpp @@ -1938,17 +1938,17 @@ error_code raw_spu_destroy(ppu_thread& ppu, u32 id) // Clear interrupt handlers for (auto& intr : thread->int_ctrl) { - if (auto tag = intr.tag.lock()) + if (auto& tag = intr.tag; tag && tag->exists) { - if (auto handler = tag->handler.lock()) + if (auto& handler = tag->handler; handler && handler->exists) { // SLEEP lv2_obj::sleep(ppu); handler->join(); - to_remove.emplace_back(std::move(handler), +handler->id); + to_remove.emplace_back(handler, handler->id); } - to_remove.emplace_back(std::move(tag), +tag->id); + to_remove.emplace_back(tag, tag->id); } } @@ -2023,7 +2023,7 @@ error_code raw_spu_create_interrupt_tag(u32 id, u32 class_id, u32 /*hwthread*/, auto& int_ctrl = thread->int_ctrl[class_id]; - if (!int_ctrl.tag.expired()) + if (int_ctrl.tag && int_ctrl.tag->exists) { error = CELL_EAGAIN; return result; diff --git a/rpcs3/rpcs3qt/kernel_explorer.cpp b/rpcs3/rpcs3qt/kernel_explorer.cpp index 1a70a4012e..c6c96b9751 100644 --- a/rpcs3/rpcs3qt/kernel_explorer.cpp +++ b/rpcs3/rpcs3qt/kernel_explorer.cpp @@ -350,9 +350,9 @@ void kernel_explorer::Update() case SYS_INTR_TAG_OBJECT: { auto& tag = static_cast(obj); - auto handler = tag.handler.lock(); + const auto handler = tag.handler.get(); - if (handler && handler.get() == idm::check_unlocked(handler->id)) + if (handler && handler->exists) { add_leaf(node, qstr(fmt::format("Intr Tag 0x%08x, Handler: 0x%08x", id, handler->id))); break;