mirror of
https://github.com/RPCS3/rpcs3.git
synced 2025-01-30 12:32:43 +00:00
Util/fixed_typemap.hpp: Fix thread-safety issue with init
Now safe as long as no- object is created
This commit is contained in:
parent
2190419b83
commit
14c92efd38
@ -396,15 +396,17 @@ namespace stx
|
||||
}
|
||||
|
||||
// Explicitly initialize object of type T possibly with dynamic type As and arguments
|
||||
template <typename T, typename As = T, typename... Args>
|
||||
template <typename T, typename As = T, typename... Args> requires (std::is_constructible_v<std::decay_t<As>, Args&&...>)
|
||||
As* init(Args&&... args) noexcept
|
||||
{
|
||||
if (std::exchange(m_init[stx::typeindex<typeinfo, std::decay_t<T>, std::decay_t<As>>()], true))
|
||||
if (m_init[stx::typeindex<typeinfo, std::decay_t<T>, std::decay_t<As>>()])
|
||||
{
|
||||
// Already exists, recreation is not supported (may be added later)
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
m_init[stx::typeindex<typeinfo, std::decay_t<T>, std::decay_t<As>>()] = true;
|
||||
|
||||
As* obj = nullptr;
|
||||
|
||||
g_tls_serialize_name = get_name<T, As>();
|
||||
@ -471,7 +473,7 @@ namespace stx
|
||||
{
|
||||
if (is_init<T>())
|
||||
{
|
||||
[[likely]] return &get<T>();
|
||||
[[likely]] return std::addressof(get<T>());
|
||||
}
|
||||
|
||||
[[unlikely]] return nullptr;
|
||||
|
Loading…
x
Reference in New Issue
Block a user