IDM: Optimize IDs for concurrency

This commit is contained in:
Elad
2026-07-14 12:15:23 +03:00
parent d755124c48
commit 2cacaa2da4
+24 -3
View File
@@ -802,9 +802,16 @@ public:
{ {
stx::shared_ptr<T> ptr; stx::shared_ptr<T> ptr;
{ {
const u32 index = get_index<Get>(id);
if (index >= id_manager::id_traits<Get>::count)
{
return false;
}
std::lock_guard lock(id_manager::g_mutex); std::lock_guard lock(id_manager::g_mutex);
if (const auto found = find_id<T, Get>(id); found.first) if (const auto found = find_index<T, Get>(index, id); found.first)
{ {
ptr = found.first->exchange(null_ptr); ptr = found.first->exchange(null_ptr);
found.second->clear(); found.second->clear();
@@ -834,9 +841,16 @@ public:
{ {
stx::shared_ptr<T> ptr; stx::shared_ptr<T> ptr;
{ {
const u32 index = get_index<Get>(id);
if (index >= id_manager::id_traits<Get>::count)
{
return false;
}
[[maybe_unused]] std::conditional_t<!!Lock(), std::lock_guard<shared_mutex>, const shared_mutex&> lock(id_manager::g_mutex); [[maybe_unused]] std::conditional_t<!!Lock(), std::lock_guard<shared_mutex>, const shared_mutex&> lock(id_manager::g_mutex);
if (const auto found = find_id<T, Get>(id); found.first && found.first->is_equal(sptr)) if (const auto found = find_index<T, Get>(index, id); found.first && found.first->is_equal(sptr))
{ {
ptr = found.first->exchange(null_ptr); ptr = found.first->exchange(null_ptr);
found.second->clear(); found.second->clear();
@@ -866,9 +880,16 @@ public:
{ {
stx::shared_ptr<Get> ptr; stx::shared_ptr<Get> ptr;
{ {
const u32 index = get_index<Get>(id);
if (index >= id_manager::id_traits<Get>::count)
{
return ptr;
}
[[maybe_unused]] std::conditional_t<!!Lock(), std::lock_guard<shared_mutex>, const shared_mutex&> lock(id_manager::g_mutex); [[maybe_unused]] std::conditional_t<!!Lock(), std::lock_guard<shared_mutex>, const shared_mutex&> lock(id_manager::g_mutex);
if (const auto found = find_id<T, Get>(id); found.first) if (const auto found = find_index<T, Get>(index, id); found.first)
{ {
ptr = static_cast<stx::shared_ptr<Get>>(found.first->exchange(null_ptr)); ptr = static_cast<stx::shared_ptr<Get>>(found.first->exchange(null_ptr));
found.second->clear(); found.second->clear();