mirror of
https://github.com/RPCS3/rpcs3.git
synced 2025-08-08 09:09:46 +00:00
fixed_typemap.hpp: remove <algorithm> dep in header
Create fixed_typemap.cpp
This commit is contained in:
parent
bacd1698fc
commit
4474757162
5 changed files with 39 additions and 14 deletions
|
@ -30,6 +30,7 @@ target_sources(rpcs3_emu PRIVATE
|
||||||
../util/atomic.cpp
|
../util/atomic.cpp
|
||||||
../util/atomic2.cpp
|
../util/atomic2.cpp
|
||||||
../util/shared_cptr.cpp
|
../util/shared_cptr.cpp
|
||||||
|
../util/fixed_typemap.cpp
|
||||||
../../Utilities/bin_patch.cpp
|
../../Utilities/bin_patch.cpp
|
||||||
../../Utilities/cond.cpp
|
../../Utilities/cond.cpp
|
||||||
../../Utilities/Config.cpp
|
../../Utilities/Config.cpp
|
||||||
|
|
|
@ -88,6 +88,9 @@
|
||||||
<ClCompile Include="util\shared_cptr.cpp">
|
<ClCompile Include="util\shared_cptr.cpp">
|
||||||
<PrecompiledHeader>NotUsing</PrecompiledHeader>
|
<PrecompiledHeader>NotUsing</PrecompiledHeader>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="util\fixed_typemap.cpp">
|
||||||
|
<PrecompiledHeader>NotUsing</PrecompiledHeader>
|
||||||
|
</ClCompile>
|
||||||
<ClCompile Include="..\Utilities\bin_patch.cpp">
|
<ClCompile Include="..\Utilities\bin_patch.cpp">
|
||||||
<PrecompiledHeader>NotUsing</PrecompiledHeader>
|
<PrecompiledHeader>NotUsing</PrecompiledHeader>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
|
|
@ -869,6 +869,9 @@
|
||||||
<ClCompile Include="util\shared_cptr.cpp">
|
<ClCompile Include="util\shared_cptr.cpp">
|
||||||
<Filter>Utilities</Filter>
|
<Filter>Utilities</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="util\fixed_typemap.cpp">
|
||||||
|
<Filter>Utilities</Filter>
|
||||||
|
</ClCompile>
|
||||||
<ClCompile Include="Crypto\aesni.cpp">
|
<ClCompile Include="Crypto\aesni.cpp">
|
||||||
<Filter>Crypto</Filter>
|
<Filter>Crypto</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
|
15
rpcs3/util/fixed_typemap.cpp
Normal file
15
rpcs3/util/fixed_typemap.cpp
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
#include "fixed_typemap.hpp"
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
namespace stx::detail
|
||||||
|
{
|
||||||
|
void destroy_info::sort_by_reverse_creation_order(destroy_info* begin, destroy_info* end)
|
||||||
|
{
|
||||||
|
std::sort(begin, end, [](const destroy_info& a, const destroy_info& b)
|
||||||
|
{
|
||||||
|
// Destroy order is the inverse of creation order
|
||||||
|
return a.created > b.created;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,13 +1,27 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <typeinfo>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
#include <algorithm>
|
|
||||||
#include <util/typeindices.hpp>
|
#include <util/typeindices.hpp>
|
||||||
|
|
||||||
namespace stx
|
namespace stx
|
||||||
{
|
{
|
||||||
|
namespace detail
|
||||||
|
{
|
||||||
|
// Destroy list element
|
||||||
|
struct destroy_info
|
||||||
|
{
|
||||||
|
void** object_pointer;
|
||||||
|
unsigned long long created;
|
||||||
|
void(*destroy)(void*& ptr) noexcept;
|
||||||
|
const char* name;
|
||||||
|
|
||||||
|
static void sort_by_reverse_creation_order(destroy_info* begin, destroy_info* end);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
// Typemap with exactly one object of each used type, created on init() and destroyed on clear()
|
// Typemap with exactly one object of each used type, created on init() and destroyed on clear()
|
||||||
template <typename /*Tag*/, bool Report = true>
|
template <typename /*Tag*/, bool Report = true>
|
||||||
class manual_fixed_typemap
|
class manual_fixed_typemap
|
||||||
|
@ -111,14 +125,7 @@ namespace stx
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Destroy list element
|
using detail::destroy_info;
|
||||||
struct destroy_info
|
|
||||||
{
|
|
||||||
void** object_pointer;
|
|
||||||
unsigned long long created;
|
|
||||||
void(*destroy)(void*& ptr) noexcept;
|
|
||||||
const char* name;
|
|
||||||
};
|
|
||||||
|
|
||||||
auto all_data = std::make_unique<destroy_info[]>(stx::typelist<typeinfo>().count());
|
auto all_data = std::make_unique<destroy_info[]>(stx::typelist<typeinfo>().count());
|
||||||
|
|
||||||
|
@ -145,11 +152,7 @@ namespace stx
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sort destroy list according to absolute creation order
|
// Sort destroy list according to absolute creation order
|
||||||
std::sort(all_data.get(), all_data.get() + _max, [](const destroy_info& a, const destroy_info& b)
|
destroy_info::sort_by_reverse_creation_order(all_data.get(), all_data.get() + _max);
|
||||||
{
|
|
||||||
// Destroy order is the inverse of creation order
|
|
||||||
return a.created > b.created;
|
|
||||||
});
|
|
||||||
|
|
||||||
// Destroy objects in correct order
|
// Destroy objects in correct order
|
||||||
for (unsigned i = 0; i < _max; i++)
|
for (unsigned i = 0; i < _max; i++)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue