diff --git a/rpcs3/Emu/Cell/lv2/sys_config.cpp b/rpcs3/Emu/Cell/lv2/sys_config.cpp index 92511df5d8..b98e925307 100644 --- a/rpcs3/Emu/Cell/lv2/sys_config.cpp +++ b/rpcs3/Emu/Cell/lv2/sys_config.cpp @@ -72,8 +72,13 @@ void dump_buffer(std::string& out, const std::vector& buffer) // LV2 Config -void lv2_config::initialize() const +void lv2_config::initialize() { + if (m_state || !m_state.compare_and_swap_test(0, 1)) + { + return; + } + // Register padmanager service, notifying vsh that a controller is connected static const u8 hid_info[0x1a] = { 0x01, 0x01, // 2 unk @@ -258,7 +263,8 @@ error_code sys_config_open(u32 equeue_hdl, vm::ptr out_config_hdl) } // Initialize lv2_config global state - if (auto global = lv2_config::make()) + const auto global = g_fxo->get(); + if (true) { global->initialize(); } @@ -301,7 +307,7 @@ error_code sys_config_get_service_event(u32 config_hdl, u32 event_id, vm::ptrfind_event(event_id); + const auto event = g_fxo->get()->find_event(event_id); if (!event) { return CELL_ESRCH; diff --git a/rpcs3/Emu/Cell/lv2/sys_config.h b/rpcs3/Emu/Cell/lv2/sys_config.h index aa6064c7c1..641980850d 100644 --- a/rpcs3/Emu/Cell/lv2/sys_config.h +++ b/rpcs3/Emu/Cell/lv2/sys_config.h @@ -125,7 +125,10 @@ static_assert(sizeof(sys_config_padmanager_data_t) == 26); * Global (fxm-managed) sys_config state */ -class lv2_config { +class lv2_config +{ + atomic_t m_state = 0; + // LV2 Config mutex shared_mutex m_mutex; @@ -133,7 +136,7 @@ class lv2_config { std::unordered_map> events; public: - void initialize() const; + void initialize(); // Service Events void add_service_event(const std::shared_ptr& event); @@ -155,17 +158,6 @@ public: return nullptr; } - - // Utilities - static std::shared_ptr make() - { - return fxm::make(); - } - - static std::shared_ptr get() - { - return fxm::get(); - } }; /* @@ -395,7 +387,7 @@ public: { auto ev = std::make_shared(std::forward(args)...); - lv2_config::get()->add_service_event(ev); + g_fxo->get()->add_service_event(ev); return std::move(ev); } @@ -403,7 +395,10 @@ public: // Destructor ~lv2_config_service_event() { - lv2_config::get()->remove_service_event(id); + if (auto global = g_fxo->get()) + { + global->remove_service_event(id); + } } // Notify queue that this event exists