Skip to content

Commit

Permalink
Update shared resource path registry
Browse files Browse the repository at this point in the history
  • Loading branch information
psiberx committed Jul 28, 2024
1 parent 2b46c88 commit 24e6b16
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
14 changes: 8 additions & 6 deletions src/App/Shared/ResourcePathRegistry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace
{
constexpr auto SharedName = Red::CName("ResourcePathRegistryV2" BUILD_SUFFIX);
constexpr auto SharedName = Red::CName("ResourcePathRegistryV3" BUILD_SUFFIX);
}

App::ResourcePathRegistry::ResourcePathRegistry(const std::filesystem::path& aPreloadPath)
Expand All @@ -16,11 +16,12 @@ App::ResourcePathRegistry::ResourcePathRegistry(const std::filesystem::path& aPr

void App::ResourcePathRegistry::OnBootstrap()
{
std::unique_lock lock(s_instance->m_mutex);
std::unique_lock lock(s_instance->m_lock);

if (!s_instance->m_hooked)
if (!s_instance->m_initialized)
{
s_instance->m_hooked = true;
s_instance->m_initialized = true;
s_instance->m_map.reserve(400000);

HookAfter<Raw::ResourcePath::Create>(&OnCreatePath);
}
Expand Down Expand Up @@ -48,7 +49,8 @@ void App::ResourcePathRegistry::OnCreatePath(Red::ResourcePath* aPath, Red::Stri
{
if (aPathStr)
{
std::scoped_lock _(s_instance->m_mutex);
std::scoped_lock _(s_instance->m_lock);
auto size = s_instance->m_map.size();
s_instance->m_map[*aPath] = {aPathStr->data, aPathStr->size};
}
}
Expand All @@ -58,7 +60,7 @@ std::string_view App::ResourcePathRegistry::ResolvePath(Red::ResourcePath aPath)
if (!aPath)
return {};

std::shared_lock _(s_instance->m_mutex);
std::shared_lock _(s_instance->m_lock);
const auto& it = s_instance->m_map.find(aPath);

if (it == s_instance->m_map.end())
Expand Down
4 changes: 2 additions & 2 deletions src/App/Shared/ResourcePathRegistry.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ class ResourcePathRegistry
protected:
struct SharedInstance
{
std::shared_mutex m_mutex;
Red::SharedSpinLock m_lock;
Core::Map<Red::ResourcePath, std::string> m_map;
bool m_preloaded{false};
bool m_hooked{false};
bool m_initialized{false};
};

void OnBootstrap() override;
Expand Down

0 comments on commit 24e6b16

Please sign in to comment.