resources are not required to be sorted

This commit is contained in:
serxa 2024-10-23 15:50:14 +00:00
parent 2ab4c0b57c
commit a886dc7c38

View File

@ -490,16 +490,15 @@ void IOResourceManager::Resource::forEachResourceNode(IResourceManager::VisitorF
void IOResourceManager::forEachNode(IResourceManager::VisitorFunc visitor)
{
// Gather resource upfront to avoid holding mutex for a long time
std::map<String, ResourcePtr> sorted_resources;
// Copy resource to avoid holding mutex for a long time
std::unordered_map<String, ResourcePtr> resources_copy;
{
std::unique_lock lock{mutex};
for (auto & [resource_name, resource] : resources)
sorted_resources[resource_name] = resource;
resources_copy = resources;
}
/// Run tasks one by one to avoid concurrent calls to visitor
for (auto & [resource_name, resource] : sorted_resources)
for (auto & [resource_name, resource] : resources_copy)
resource->forEachResourceNode(visitor);
}