From 14c92efd38979165b9236f65dac141c0d93bc8a8 Mon Sep 17 00:00:00 2001 From: Elad Ashkenazi Date: Fri, 15 Dec 2023 16:32:33 +0200 Subject: [PATCH] Util/fixed_typemap.hpp: Fix thread-safety issue with init Now safe as long as no- object is created --- rpcs3/util/fixed_typemap.hpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/rpcs3/util/fixed_typemap.hpp b/rpcs3/util/fixed_typemap.hpp index b8844e22a6..4df9c57891 100644 --- a/rpcs3/util/fixed_typemap.hpp +++ b/rpcs3/util/fixed_typemap.hpp @@ -396,15 +396,17 @@ namespace stx } // Explicitly initialize object of type T possibly with dynamic type As and arguments - template + template requires (std::is_constructible_v, Args&&...>) As* init(Args&&... args) noexcept { - if (std::exchange(m_init[stx::typeindex, std::decay_t>()], true)) + if (m_init[stx::typeindex, std::decay_t>()]) { // Already exists, recreation is not supported (may be added later) return nullptr; } + m_init[stx::typeindex, std::decay_t>()] = true; + As* obj = nullptr; g_tls_serialize_name = get_name(); @@ -471,7 +473,7 @@ namespace stx { if (is_init()) { - [[likely]] return &get(); + [[likely]] return std::addressof(get()); } [[unlikely]] return nullptr;