From eb889920e69a7faabd981602a3ed527cea07f293 Mon Sep 17 00:00:00 2001 From: Nekotekina Date: Tue, 21 Jun 2016 11:22:30 +0300 Subject: [PATCH] IdManager fix Debug build fixed Allowed get/remove with forward declarations --- rpcs3/Emu/IdManager.cpp | 4 +-- rpcs3/Emu/IdManager.h | 55 ++++++++++++++++++++++++++++++----------- 2 files changed, 42 insertions(+), 17 deletions(-) diff --git a/rpcs3/Emu/IdManager.cpp b/rpcs3/Emu/IdManager.cpp index e2bef6e4b4..639b3c7c0f 100644 --- a/rpcs3/Emu/IdManager.cpp +++ b/rpcs3/Emu/IdManager.cpp @@ -15,11 +15,11 @@ std::vector& id_manager::typeinfo::access() return list; } -u32 id_manager::typeinfo::add_type(typeinfo info) +u32 id_manager::typeinfo::add_type() { auto& list = access(); - list.emplace_back(info); + list.emplace_back(); return ::size32(list) - 1; } diff --git a/rpcs3/Emu/IdManager.h b/rpcs3/Emu/IdManager.h index 964661661a..bc9ac403fd 100644 --- a/rpcs3/Emu/IdManager.h +++ b/rpcs3/Emu/IdManager.h @@ -80,20 +80,30 @@ namespace id_manager static std::vector& access(); // Add to the global list - static u32 add_type(typeinfo info); + static u32 add_type(); public: - void(*on_init)(void*); - void(*on_stop)(void*); + void(*on_init)(void*) = nullptr; + void(*on_stop)(void*) = nullptr; // Get type index template static inline u32 get_index() { - // Forbid forward declarations (It'd be better to allow them sometimes but it seems too dangerous) + return registered::index; + } + + // Register functions + template + static inline void update() + { + // Forbid forward declarations static constexpr auto size = sizeof(std::conditional_t::value, void*, T>); - return registered::index; + auto& info = access()[get_index()]; + + info.on_init = [](void* ptr) { return_ id_manager::on_init::func(static_cast(ptr)); }; + info.on_stop = [](void* ptr) { return_ id_manager::on_stop::func(static_cast(ptr)); }; } // Read all registered types @@ -101,14 +111,16 @@ namespace id_manager { return access(); } + + template + static inline auto get_stop() + { + return access()[get_index()].on_stop; + } }; template - const u32 typeinfo::registered::index = typeinfo::add_type( - { - PURE_EXPR(id_manager::on_init::func(static_cast(ptr)), void* ptr), - PURE_EXPR(id_manager::on_stop::func(static_cast(ptr)), void* ptr), - }); + const u32 typeinfo::registered::index = typeinfo::add_type(); } // Object manager for emulated process. Multiple objects of specified arbitrary type are given unique IDs. @@ -198,6 +210,9 @@ class idm template static map_type::pointer create_id(F&& provider) { + id_manager::typeinfo::update(); + id_manager::typeinfo::update::tag>(); + writer_lock lock(g_mutex); if (auto place = allocate_id(get_tag(), id_manager::id_traits::min, id_manager::id_traits::max)) @@ -374,7 +389,7 @@ public: if (LIKELY(ptr)) { - id_manager::on_stop::func(static_cast(ptr.get())); + id_manager::typeinfo::get_stop()(static_cast(ptr.get())); } return ptr.operator bool(); @@ -388,7 +403,7 @@ public: if (LIKELY(ptr)) { - id_manager::on_stop::func(static_cast(ptr.get())); + id_manager::typeinfo::get_stop()(static_cast(ptr.get())); } return{ ptr, static_cast(ptr.get()) }; @@ -414,7 +429,7 @@ public: g_map[get_type()].erase(id); } - id_manager::on_stop::func(static_cast(ptr.get())); + id_manager::typeinfo::get_stop()(static_cast(ptr.get())); return{ ptr, static_cast(ptr.get()) }; } @@ -447,6 +462,8 @@ public: template static std::enable_if_t::value, std::shared_ptr> make(Args&&... args) { + id_manager::typeinfo::update(); + std::shared_ptr ptr; { writer_lock lock(g_mutex); @@ -471,6 +488,8 @@ public: template static std::enable_if_t::value, std::shared_ptr> make_always(Args&&... args) { + id_manager::typeinfo::update(); + std::shared_ptr ptr; std::shared_ptr old; { @@ -495,6 +514,8 @@ public: template static auto import(F&& provider) -> decltype(static_cast>(provider())) { + id_manager::typeinfo::update(); + std::shared_ptr ptr; { writer_lock lock(g_mutex); @@ -519,6 +540,8 @@ public: template static auto import_always(F&& provider) -> decltype(static_cast>(provider())) { + id_manager::typeinfo::update(); + std::shared_ptr ptr; std::shared_ptr old; { @@ -543,6 +566,8 @@ public: template static std::enable_if_t::value, std::shared_ptr> get_always(Args&&... args) { + id_manager::typeinfo::update(); + std::shared_ptr ptr; { writer_lock lock(g_mutex); @@ -591,7 +616,7 @@ public: if (ptr) { - id_manager::on_stop::func(static_cast(ptr.get())); + id_manager::typeinfo::get_stop()(static_cast(ptr.get())); } return ptr.operator bool(); @@ -605,7 +630,7 @@ public: if (ptr) { - id_manager::on_stop::func(static_cast(ptr.get())); + id_manager::typeinfo::get_stop()(static_cast(ptr.get())); } return{ ptr, static_cast(ptr.get()) };