mirror of
https://github.com/RPCS3/rpcs3.git
synced 2025-07-05 22:41:25 +12: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
1 changed files with 5 additions and 3 deletions
|
@ -396,15 +396,17 @@ namespace stx
|
||||||
}
|
}
|
||||||
|
|
||||||
// Explicitly initialize object of type T possibly with dynamic type As and arguments
|
// 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
|
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)
|
// Already exists, recreation is not supported (may be added later)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m_init[stx::typeindex<typeinfo, std::decay_t<T>, std::decay_t<As>>()] = true;
|
||||||
|
|
||||||
As* obj = nullptr;
|
As* obj = nullptr;
|
||||||
|
|
||||||
g_tls_serialize_name = get_name<T, As>();
|
g_tls_serialize_name = get_name<T, As>();
|
||||||
|
@ -471,7 +473,7 @@ namespace stx
|
||||||
{
|
{
|
||||||
if (is_init<T>())
|
if (is_init<T>())
|
||||||
{
|
{
|
||||||
[[likely]] return &get<T>();
|
[[likely]] return std::addressof(get<T>());
|
||||||
}
|
}
|
||||||
|
|
||||||
[[unlikely]] return nullptr;
|
[[unlikely]] return nullptr;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue