diff --git a/Utilities/Thread.h b/Utilities/Thread.h index 7f2e0b522f..39285904ee 100644 --- a/Utilities/Thread.h +++ b/Utilities/Thread.h @@ -693,7 +693,7 @@ public: if constexpr (std::is_assignable_v) { - static_cast(*this) = s; + static_cast(*this) = thread_state::aborting; } if (notify_sync) @@ -706,6 +706,11 @@ public: { // This participates in emulation stopping, use destruction-alike semantics thread::join(true); + + if constexpr (std::is_assignable_v) + { + static_cast(*this) = thread_state::finished; + } } return *this; diff --git a/rpcs3/Emu/Cell/lv2/sys_config.cpp b/rpcs3/Emu/Cell/lv2/sys_config.cpp index 8194fb222b..c39444ccd0 100644 --- a/rpcs3/Emu/Cell/lv2/sys_config.cpp +++ b/rpcs3/Emu/Cell/lv2/sys_config.cpp @@ -109,10 +109,29 @@ void lv2_config::add_service_event(shared_ptr event) void lv2_config::remove_service_event(u32 id) { + shared_ptr ptr; + std::lock_guard lock(m_mutex); - events.erase(id); + + if (auto it = events.find(id); it != events.end()) + { + ptr = std::move(it->second); + events.erase(it); + } } +lv2_config_service_event& lv2_config_service_event::operator=(thread_state s) noexcept +{ + if (s == thread_state::finished) + { + if (auto global = g_fxo->try_get()) + { + global->remove_service_event(id); + } + } + + return *this; +} // LV2 Config Service Listener bool lv2_config_service_listener::check_service(const lv2_config_service& service) const diff --git a/rpcs3/Emu/Cell/lv2/sys_config.h b/rpcs3/Emu/Cell/lv2/sys_config.h index 337ffbe74f..3915dfc8cb 100644 --- a/rpcs3/Emu/Cell/lv2/sys_config.h +++ b/rpcs3/Emu/Cell/lv2/sys_config.h @@ -390,13 +390,9 @@ public: } // Destructor - ~lv2_config_service_event() noexcept - { - if (auto global = g_fxo->try_get()) - { - global->remove_service_event(id); - } - } + lv2_config_service_event& operator=(thread_state s) noexcept; + + ~lv2_config_service_event() noexcept = default; // Notify queue that this event exists bool notify() const; diff --git a/rpcs3/Emu/IdManager.h b/rpcs3/Emu/IdManager.h index bf128a393f..b555907d13 100644 --- a/rpcs3/Emu/IdManager.h +++ b/rpcs3/Emu/IdManager.h @@ -801,6 +801,15 @@ public: } } + if constexpr (std::is_assignable_v) + { + if (ptr) + { + constexpr thread_state finished{3}; + *static_cast(ptr.get()) = finished; + } + } + return true; } @@ -824,6 +833,15 @@ public: } } + if constexpr (std::is_assignable_v) + { + if (ptr) + { + constexpr thread_state finished{3}; + *static_cast(ptr.get()) = finished; + } + } + return true; }