summaryrefslogtreecommitdiff
path: root/view/sharedcache/core/SharedCache.cpp
diff options
context:
space:
mode:
authorMason Reed <mason@vector35.com>2025-04-06 21:10:38 -0400
committerMason Reed <mason@vector35.com>2025-04-06 21:11:00 -0400
commit05e3335c27a477492fee6d031654dd3152f722b6 (patch)
tree7b85282b3f93662bf5ebcbde4a19ab462d8651c0 /view/sharedcache/core/SharedCache.cpp
parent833375c0199d4e7c2555e6e9f14862ddc3ca120c (diff)
[SharedCache] Add mutex to guard `m_namedSymbols`
It is modified on a worker thread so if a user tries to call `GetSymbolWithName` after view init but before the processing on the worker thread finishes, there would have been issues!
Diffstat (limited to 'view/sharedcache/core/SharedCache.cpp')
-rw-r--r--view/sharedcache/core/SharedCache.cpp5
1 files changed, 4 insertions, 1 deletions
diff --git a/view/sharedcache/core/SharedCache.cpp b/view/sharedcache/core/SharedCache.cpp
index 936dca4d..e468b559 100644
--- a/view/sharedcache/core/SharedCache.cpp
+++ b/view/sharedcache/core/SharedCache.cpp
@@ -149,6 +149,7 @@ SharedCache::SharedCache(uint64_t addressSize)
{
m_addressSize = addressSize;
m_vm = std::make_shared<VirtualMemory>();
+ m_namedSymMutex = std::make_unique<std::shared_mutex>();
}
@@ -437,6 +438,7 @@ void SharedCache::ProcessEntrySlideInfo(const CacheEntry& entry) const
void SharedCache::ProcessSymbols()
{
+ std::unique_lock<std::shared_mutex> lock(*m_namedSymMutex);
// Populate the named symbols from the regular symbols map.
m_namedSymbols.reserve(m_symbols.size());
for (const auto& [address, symbol] : m_symbols)
@@ -520,8 +522,9 @@ std::optional<CacheSymbol> SharedCache::GetSymbolAt(uint64_t address) const
return it->second;
}
-std::optional<CacheSymbol> SharedCache::GetSymbolWithName(const std::string& name) const
+std::optional<CacheSymbol> SharedCache::GetSymbolWithName(const std::string& name)
{
+ std::shared_lock<std::shared_mutex> lock(*m_namedSymMutex);
const auto it = m_namedSymbols.find(name);
if (it == m_namedSymbols.end())
return std::nullopt;