diff --git a/rpcs3/Emu/System.cpp b/rpcs3/Emu/System.cpp index 209795156f..c3ad49ca5a 100644 --- a/rpcs3/Emu/System.cpp +++ b/rpcs3/Emu/System.cpp @@ -1542,31 +1542,23 @@ void Emulator::Stop(bool restart) cpu_thread::stop_all(); - using fxo_t = std::remove_pointer_t; - // Signal threads - for (const auto& type : fxo_t::view_typelist()) + for (const auto& [type, data] : *g_fxo) { if (type.stop) { - if (auto data = g_fxo->try_get(type)) - { - type.stop(data, thread_state::aborting); - } + type.stop(data, thread_state::aborting); } } GetCallbacks().on_stop(); // Join threads - for (const auto& type : fxo_t::view_typelist()) + for (const auto& [type, data] : *g_fxo) { if (type.stop) { - if (auto data = g_fxo->try_get(type)) - { - type.stop(data, thread_state::finished); - } + type.stop(data, thread_state::finished); } } diff --git a/rpcs3/util/fixed_typemap.hpp b/rpcs3/util/fixed_typemap.hpp index 64d2f8787b..850868f134 100644 --- a/rpcs3/util/fixed_typemap.hpp +++ b/rpcs3/util/fixed_typemap.hpp @@ -155,8 +155,8 @@ namespace stx clear(); } - m_order = new void*[stx::typelist().count()]; - m_info = new const typeinfo*[stx::typelist().count()]; + m_order = new void*[stx::typelist().count() + 1]; + m_info = new const typeinfo*[stx::typelist().count() + 1]; m_init = new bool[stx::typelist().count()]{}; if constexpr (Size == 0) @@ -176,6 +176,9 @@ namespace stx ensure(Align >= stx::typelist().align()); m_data[0] = 0; } + + *m_order++ = nullptr; + *m_info++ = nullptr; } void init(bool reset = true) @@ -231,6 +234,8 @@ namespace stx } // Pointers should be restored to their positions + m_info--; + m_order--; delete[] m_init; delete[] m_info; delete[] m_order; @@ -344,20 +349,51 @@ namespace stx [[unlikely]] return nullptr; } - static const auto& view_typelist() noexcept + class iterator { - return stx::typelist(); - } + const typeinfo** m_info; + void** m_ptr; - // Get type-erased raw pointer to storage of type - uchar* try_get(const type_info& type) const noexcept - { - if (m_init[type.index()]) + public: + iterator(const typeinfo** _info, void** _ptr) + : m_info(_info) + , m_ptr(_ptr) { - [[likely]] return (Size ? +m_data : m_list) + type.pos(); } - [[unlikely]] return nullptr; + std::pair operator*() const + { + return {*m_info[-1], m_ptr[-1]}; + } + + iterator& operator++() + { + m_info--; + m_ptr--; + + if (!m_info[-1]) + { + m_info = nullptr; + m_ptr = nullptr; + } + + return *this; + } + + bool operator!=(const iterator& rhs) const + { + return m_info != rhs.m_info || m_ptr != rhs.m_ptr; + } + }; + + iterator begin() noexcept + { + return iterator{m_info, m_order}; + } + + iterator end() noexcept + { + return iterator{nullptr, nullptr}; } }; } diff --git a/rpcs3/util/types.hpp b/rpcs3/util/types.hpp index b7f698cac6..736236a785 100644 --- a/rpcs3/util/types.hpp +++ b/rpcs3/util/types.hpp @@ -761,7 +761,7 @@ constexpr unsigned __builtin_COLUMN() } #endif -template +template struct const_str_t { static constexpr usz size = Size; @@ -792,7 +792,7 @@ struct const_str_t }; template <> -struct const_str_t +struct const_str_t { const usz size;