Fix idm::allocate_id at fixed position

This commit is contained in:
Eladash 2023-12-28 19:37:24 +02:00 committed by Elad Ashkenazi
parent 72ed2f1d43
commit 526aaf7302
4 changed files with 26 additions and 10 deletions

View File

@ -3019,7 +3019,7 @@ std::pair<std::shared_ptr<lv2_overlay>, CellError> ppu_load_overlay(const ppu_ex
if (!ar && !virtual_load)
{
idm::import_existing<lv2_obj, lv2_overlay>(ovlm);
ensure(idm::import_existing<lv2_obj, lv2_overlay>(ovlm));
try_spawn_ppu_if_exclusive_program(*ovlm);
}

View File

@ -227,8 +227,8 @@ lv2_spu_group::lv2_spu_group(utils::serial& ar) noexcept
if (ar.pop<bool>())
{
ar(id_manager::g_id);
thread = std::make_shared<named_thread<spu_thread>>(ar, this);
idm::import_existing<named_thread<spu_thread>>(thread, idm::last_id());
thread = std::make_shared<named_thread<spu_thread>>(stx::launch_retainer{}, ar, this);
ensure(idm::import_existing<named_thread<spu_thread>>(thread, idm::last_id()));
running += !thread->stop_flag_removal_protection;
}
}

View File

@ -35,10 +35,13 @@ std::vector<std::pair<u128, id_manager::typeinfo>>& id_manager::get_typeinfo_map
idm::map_data* idm::allocate_id(std::vector<map_data>& vec, u32 type_id, u32 dst_id, u32 base, u32 step, u32 count, bool uses_lowest_id, std::pair<u32, u32> invl_range)
{
if (const u32 index = id_manager::get_index(dst_id, base, step, count, invl_range); index < count)
if (dst_id != (base ? 0 : u32{umax}))
{
// Fixed position construction
ensure(index < vec.size());
const u32 index = id_manager::get_index(dst_id, base, step, count, invl_range);
ensure(index < count);
vec.resize(std::max<usz>(vec.size(), index + 1));
if (vec[index].second)
{

View File

@ -102,13 +102,26 @@ namespace id_manager
template <typename T, typename = void>
struct id_traits_load_func
{
static constexpr std::shared_ptr<void>(*load)(utils::serial&) = [](utils::serial& ar) -> std::shared_ptr<void> { return std::make_shared<T>(stx::exact_t<utils::serial&>(ar)); };
static constexpr std::shared_ptr<void>(*load)(utils::serial&) = [](utils::serial& ar) -> std::shared_ptr<void>
{
if constexpr (std::is_constructible_v<T, stx::exact_t<const stx::launch_retainer&>, stx::exact_t<utils::serial&>>)
{
return std::make_shared<T>(stx::launch_retainer{}, stx::exact_t<utils::serial&>(ar));
}
else
{
return std::make_shared<T>(stx::exact_t<utils::serial&>(ar));
}
};
};
template <typename T>
struct id_traits_load_func<T, std::void_t<decltype(&T::load)>>
{
static constexpr std::shared_ptr<void>(*load)(utils::serial&) = [](utils::serial& ar) -> std::shared_ptr<void> { return T::load(stx::exact_t<utils::serial&>(ar)); };
static constexpr std::shared_ptr<void>(*load)(utils::serial&) = [](utils::serial& ar) -> std::shared_ptr<void>
{
return T::load(stx::exact_t<utils::serial&>(ar));
};
};
template <typename T, typename = void>
@ -353,11 +366,11 @@ namespace id_manager
}
id_map& operator=(thread_state state) noexcept requires (std::is_assignable_v<T&, thread_state>)
{
if (private_copy.size() != vec.size())
{
private_copy.clear();
if (!vec.empty() || !private_copy.empty())
{
reader_lock lock(g_mutex);
// Save all entries