diff --git a/rpcs3/Emu/Cell/Modules/cellAudio.cpp b/rpcs3/Emu/Cell/Modules/cellAudio.cpp index 686ca86ded..ec76cc296e 100644 --- a/rpcs3/Emu/Cell/Modules/cellAudio.cpp +++ b/rpcs3/Emu/Cell/Modules/cellAudio.cpp @@ -1575,7 +1575,7 @@ error_code AudioSetNotifyEventQueue(u64 key, u32 iFlags) return CELL_AUDIO_ERROR_TRANS_EVENT; } - if (!lv2_event_queue::check(i->port)) + if (!lv2_obj::check(i->port)) { // Cleanup, avoid cases where there are multiple ports with the same key i = g_audio.keys.erase(i); @@ -1625,7 +1625,7 @@ error_code AudioRemoveNotifyEventQueue(u64 key, u32 iFlags) for (auto i = g_audio.keys.cbegin(); i != g_audio.keys.cend(); i++) { - if (lv2_event_queue::check(i->port) && i->port->key == key) + if (lv2_obj::check(i->port) && i->port->key == key) { if (i->flags != iFlags) { diff --git a/rpcs3/Emu/Cell/SPUThread.cpp b/rpcs3/Emu/Cell/SPUThread.cpp index 602782717e..3dc07ce8ed 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 (tag && tag->exists) + if (lv2_obj::check(tag)) { - if (auto handler = tag->handler; handler && handler->exists) + if (auto handler = tag->handler; lv2_obj::check(handler)) { rlock.unlock(); handler->exec(); @@ -4379,7 +4379,7 @@ bool spu_thread::stop_and_signal(u32 code) { if (spuq == v.first) { - if (lv2_event_queue::check(v.second)) + if (lv2_obj::check(v.second)) { queue = v.second.get(); break; @@ -4499,7 +4499,7 @@ bool spu_thread::stop_and_signal(u32 code) { if (spuq == v.first) { - if (lv2_event_queue::check(v.second)) + if (lv2_obj::check(v.second)) { queue = v.second.get(); break; diff --git a/rpcs3/Emu/Cell/lv2/sys_event.cpp b/rpcs3/Emu/Cell/lv2/sys_event.cpp index 48dfdb8b32..4288534f46 100644 --- a/rpcs3/Emu/Cell/lv2/sys_event.cpp +++ b/rpcs3/Emu/Cell/lv2/sys_event.cpp @@ -32,18 +32,6 @@ std::shared_ptr lv2_event_queue::find(u64 ipc_key) return g_fxo->get>().get(ipc_key); } -bool lv2_event_queue::check(const std::weak_ptr& wkptr) -{ - const auto queue = wkptr.lock(); - - return queue && queue->exists; -} - -bool lv2_event_queue::check(const std::shared_ptr& sptr) -{ - return sptr && sptr->exists; -} - CellError lv2_event_queue::send(lv2_event event) { std::lock_guard lock(mutex); @@ -372,7 +360,7 @@ error_code sys_event_port_destroy(ppu_thread& ppu, u32 eport_id) const auto port = idm::withdraw(eport_id, [](lv2_event_port& port) -> CellError { - if (lv2_event_queue::check(port.queue)) + if (lv2_obj::check(port.queue)) { return CELL_EISCONN; } @@ -413,7 +401,7 @@ error_code sys_event_port_connect_local(cpu_thread& cpu, u32 eport_id, u32 equeu return CELL_EINVAL; } - if (lv2_event_queue::check(port->queue)) + if (lv2_obj::check(port->queue)) { return CELL_EISCONN; } @@ -450,7 +438,7 @@ error_code sys_event_port_connect_ipc(ppu_thread& ppu, u32 eport_id, u64 ipc_key return CELL_EINVAL; } - if (lv2_event_queue::check(port->queue)) + if (lv2_obj::check(port->queue)) { return CELL_EISCONN; } @@ -475,7 +463,7 @@ error_code sys_event_port_disconnect(ppu_thread& ppu, u32 eport_id) return CELL_ESRCH; } - if (!lv2_event_queue::check(port->queue)) + if (!lv2_obj::check(port->queue)) { return CELL_ENOTCONN; } @@ -498,7 +486,7 @@ error_code sys_event_port_send(u32 eport_id, u64 data1, u64 data2, u64 data3) const auto port = idm::get(eport_id, [&](lv2_event_port& port) -> CellError { - if (lv2_event_queue::check(port.queue)) + if (lv2_obj::check(port.queue)) { const u64 source = port.name ? port.name : (s64{process_getpid()} << 32) | u64{eport_id}; diff --git a/rpcs3/Emu/Cell/lv2/sys_interrupt.cpp b/rpcs3/Emu/Cell/lv2/sys_interrupt.cpp index 121dd22d30..36ed8e517d 100644 --- a/rpcs3/Emu/Cell/lv2/sys_interrupt.cpp +++ b/rpcs3/Emu/Cell/lv2/sys_interrupt.cpp @@ -63,7 +63,7 @@ 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 && tag.handler->exists) + if (lv2_obj::check(tag.handler)) { return CELL_EBUSY; } @@ -123,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 && tag->handler->exists) + if (lv2_obj::check(tag->handler)) { error = CELL_ESTAT; return result; diff --git a/rpcs3/Emu/Cell/lv2/sys_spu.cpp b/rpcs3/Emu/Cell/lv2/sys_spu.cpp index 2355346f23..66e946e41a 100644 --- a/rpcs3/Emu/Cell/lv2/sys_spu.cpp +++ b/rpcs3/Emu/Cell/lv2/sys_spu.cpp @@ -1432,7 +1432,7 @@ error_code sys_spu_thread_group_connect_event(ppu_thread& ppu, u32 id, u32 eq, u std::lock_guard lock(group->mutex); - if (lv2_event_queue::check(*ep)) + if (lv2_obj::check(*ep)) { return CELL_EBUSY; } @@ -1474,7 +1474,7 @@ error_code sys_spu_thread_group_disconnect_event(ppu_thread& ppu, u32 id, u32 et std::lock_guard lock(group->mutex); - if (!lv2_event_queue::check(*ep)) + if (!lv2_obj::check(*ep)) { return CELL_EINVAL; } @@ -1507,7 +1507,7 @@ error_code sys_spu_thread_connect_event(ppu_thread& ppu, u32 id, u32 eq, u32 et, auto& port = thread->spup[spup]; - if (lv2_event_queue::check(port)) + if (lv2_obj::check(port)) { return CELL_EISCONN; } @@ -1540,7 +1540,7 @@ error_code sys_spu_thread_disconnect_event(ppu_thread& ppu, u32 id, u32 et, u8 s auto& port = thread->spup[spup]; - if (!lv2_event_queue::check(port)) + if (!lv2_obj::check(port)) { return CELL_ENOTCONN; } @@ -1683,7 +1683,7 @@ error_code sys_spu_thread_group_connect_event_all_threads(ppu_thread& ppu, u32 i { if (t) { - if (lv2_event_queue::check(t->spup[port])) + if (lv2_obj::check(t->spup[port])) { found = false; break; @@ -1938,9 +1938,9 @@ error_code raw_spu_destroy(ppu_thread& ppu, u32 id) // Clear interrupt handlers for (auto& intr : thread->int_ctrl) { - if (auto& tag = intr.tag; tag && tag->exists) + if (auto& tag = intr.tag; lv2_obj::check(tag)) { - if (auto& handler = tag->handler; handler && handler->exists) + if (auto& handler = tag->handler; lv2_obj::check(handler)) { // SLEEP lv2_obj::sleep(ppu); @@ -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 && int_ctrl.tag->exists) + if (lv2_obj::check(int_ctrl.tag)) { error = CELL_EAGAIN; return result; diff --git a/rpcs3/Emu/Cell/lv2/sys_sync.h b/rpcs3/Emu/Cell/lv2/sys_sync.h index 0e239ccc05..44cfa719c5 100644 --- a/rpcs3/Emu/Cell/lv2/sys_sync.h +++ b/rpcs3/Emu/Cell/lv2/sys_sync.h @@ -88,6 +88,12 @@ public: // Existence validation (workaround for shared-ptr ref-counting) atomic_t exists = 0; + template + static bool check(Ptr&& ptr) + { + return ptr && ptr->exists; + } + static std::string name64(u64 name_u64) { const auto ptr = reinterpret_cast(&name_u64); diff --git a/rpcs3/Emu/Cell/lv2/sys_timer.cpp b/rpcs3/Emu/Cell/lv2/sys_timer.cpp index 983403de9f..24fee6d087 100644 --- a/rpcs3/Emu/Cell/lv2/sys_timer.cpp +++ b/rpcs3/Emu/Cell/lv2/sys_timer.cpp @@ -83,7 +83,7 @@ error_code sys_timer_destroy(ppu_thread& ppu, u32 timer_id) const auto timer = idm::withdraw(timer_id, [&](lv2_timer& timer) -> CellError { - if (reader_lock lock(timer.mutex); lv2_event_queue::check(timer.port)) + if (reader_lock lock(timer.mutex); lv2_obj::check(timer.port)) { return CELL_EISCONN; } @@ -151,7 +151,7 @@ error_code _sys_timer_start(ppu_thread& ppu, u32 timer_id, u64 base_time, u64 pe { std::unique_lock lock(timer.mutex); - if (!lv2_event_queue::check(timer.port)) + if (!lv2_obj::check(timer.port)) { return CELL_ENOTCONN; } @@ -222,7 +222,7 @@ error_code sys_timer_connect_event_queue(ppu_thread& ppu, u32 timer_id, u32 queu std::lock_guard lock(timer.mutex); - if (lv2_event_queue::check(timer.port)) + if (lv2_obj::check(timer.port)) { return CELL_EISCONN; } @@ -260,7 +260,7 @@ error_code sys_timer_disconnect_event_queue(ppu_thread& ppu, u32 timer_id) timer.state = SYS_TIMER_STATE_STOP; - if (!lv2_event_queue::check(timer.port)) + if (!lv2_obj::check(timer.port)) { return CELL_ENOTCONN; } diff --git a/rpcs3/rpcs3qt/kernel_explorer.cpp b/rpcs3/rpcs3qt/kernel_explorer.cpp index c6c96b9751..90fcc0a7f7 100644 --- a/rpcs3/rpcs3qt/kernel_explorer.cpp +++ b/rpcs3/rpcs3qt/kernel_explorer.cpp @@ -352,7 +352,7 @@ void kernel_explorer::Update() auto& tag = static_cast(obj); const auto handler = tag.handler.get(); - if (handler && handler->exists) + if (lv2_obj::check(handler)) { add_leaf(node, qstr(fmt::format("Intr Tag 0x%08x, Handler: 0x%08x", id, handler->id))); break; @@ -379,7 +379,7 @@ void kernel_explorer::Update() auto& ep = static_cast(obj); const auto type = ep.type == SYS_EVENT_PORT_LOCAL ? "LOCAL"sv : "IPC"sv; - if (const auto queue = ep.queue.get(); queue && queue->exists) + if (const auto queue = ep.queue.get(); lv2_obj::check(queue)) { if (queue == idm::check_unlocked(queue->id)) {