Use g_fxo for lv2_config

This commit is contained in:
Nekotekina 2019-08-24 19:50:34 +03:00
parent 8304043d00
commit cf44038435
2 changed files with 19 additions and 18 deletions

View file

@ -72,8 +72,13 @@ void dump_buffer(std::string& out, const std::vector<u8>& buffer)
// LV2 Config // 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 // Register padmanager service, notifying vsh that a controller is connected
static const u8 hid_info[0x1a] = { static const u8 hid_info[0x1a] = {
0x01, 0x01, // 2 unk 0x01, 0x01, // 2 unk
@ -258,7 +263,8 @@ error_code sys_config_open(u32 equeue_hdl, vm::ptr<u32> out_config_hdl)
} }
// Initialize lv2_config global state // Initialize lv2_config global state
if (auto global = lv2_config::make()) const auto global = g_fxo->get<lv2_config>();
if (true)
{ {
global->initialize(); global->initialize();
} }
@ -301,7 +307,7 @@ error_code sys_config_get_service_event(u32 config_hdl, u32 event_id, vm::ptr<sy
} }
// Find service_event object // Find service_event object
const auto event = lv2_config::get()->find_event(event_id); const auto event = g_fxo->get<lv2_config>()->find_event(event_id);
if (!event) if (!event)
{ {
return CELL_ESRCH; return CELL_ESRCH;

View file

@ -125,7 +125,10 @@ static_assert(sizeof(sys_config_padmanager_data_t) == 26);
* Global (fxm-managed) sys_config state * Global (fxm-managed) sys_config state
*/ */
class lv2_config { class lv2_config
{
atomic_t<u32> m_state = 0;
// LV2 Config mutex // LV2 Config mutex
shared_mutex m_mutex; shared_mutex m_mutex;
@ -133,7 +136,7 @@ class lv2_config {
std::unordered_map<u32, std::weak_ptr<lv2_config_service_event>> events; std::unordered_map<u32, std::weak_ptr<lv2_config_service_event>> events;
public: public:
void initialize() const; void initialize();
// Service Events // Service Events
void add_service_event(const std::shared_ptr<lv2_config_service_event>& event); void add_service_event(const std::shared_ptr<lv2_config_service_event>& event);
@ -155,17 +158,6 @@ public:
return nullptr; return nullptr;
} }
// Utilities
static std::shared_ptr<lv2_config> make()
{
return fxm::make<lv2_config>();
}
static std::shared_ptr<lv2_config> get()
{
return fxm::get<lv2_config>();
}
}; };
/* /*
@ -395,7 +387,7 @@ public:
{ {
auto ev = std::make_shared<lv2_config_service_event>(std::forward<Args>(args)...); auto ev = std::make_shared<lv2_config_service_event>(std::forward<Args>(args)...);
lv2_config::get()->add_service_event(ev); g_fxo->get<lv2_config>()->add_service_event(ev);
return std::move(ev); return std::move(ev);
} }
@ -403,7 +395,10 @@ public:
// Destructor // Destructor
~lv2_config_service_event() ~lv2_config_service_event()
{ {
lv2_config::get()->remove_service_event(id); if (auto global = g_fxo->get<lv2_config>())
{
global->remove_service_event(id);
}
} }
// Notify queue that this event exists // Notify queue that this event exists