summaryrefslogtreecommitdiff
path: root/Source/Core/Common
diff options
context:
space:
mode:
authorJosJuice <josjuice@gmail.com>2025-06-30 19:12:00 +0200
committerJosJuice <josjuice@gmail.com>2025-07-27 16:26:47 +0200
commit803e6b017bf8bb82ee65b48fa244eb1e4c89034d (patch)
treeae337c9e6d6e4787d017061b14b01c2579fcabd7 /Source/Core/Common
parent59d126d21582d2fd2df05dc33d5eeebaf097204a (diff)
PPCSymbolDB: Reduce lock contention in LoadMap/LoadMapOnBoot
By building the map in a local variable and then swapping it with the member variable, we avoid the need to hold a lock while building the map.
Diffstat (limited to 'Source/Core/Common')
-rw-r--r--Source/Core/Common/SymbolDB.cpp10
-rw-r--r--Source/Core/Common/SymbolDB.h4
2 files changed, 13 insertions, 1 deletions
diff --git a/Source/Core/Common/SymbolDB.cpp b/Source/Core/Common/SymbolDB.cpp
index 88f281e497..ad438b8277 100644
--- a/Source/Core/Common/SymbolDB.cpp
+++ b/Source/Core/Common/SymbolDB.cpp
@@ -5,6 +5,7 @@
#include <cstring>
#include <map>
+#include <mutex>
#include <string>
#include <utility>
@@ -49,6 +50,8 @@ bool SymbolDB::IsEmpty() const
bool SymbolDB::Clear(const char* prefix)
{
+ std::lock_guard lock(m_mutex);
+
// TODO: honor prefix
m_map_name.clear();
if (IsEmpty())
@@ -62,8 +65,13 @@ bool SymbolDB::Clear(const char* prefix)
void SymbolDB::Index()
{
+ Index(&m_functions);
+}
+
+void SymbolDB::Index(XFuncMap* functions)
+{
int i = 0;
- for (auto& func : m_functions)
+ for (auto& func : *functions)
{
func.second.index = i++;
}
diff --git a/Source/Core/Common/SymbolDB.h b/Source/Core/Common/SymbolDB.h
index 7763999453..69515532b1 100644
--- a/Source/Core/Common/SymbolDB.h
+++ b/Source/Core/Common/SymbolDB.h
@@ -7,6 +7,7 @@
#pragma once
#include <map>
+#include <mutex>
#include <set>
#include <string>
#include <string_view>
@@ -105,9 +106,12 @@ public:
void Index();
protected:
+ static void Index(XFuncMap* functions);
+
XFuncMap m_functions;
XNoteMap m_notes;
XFuncPtrMap m_checksum_to_function;
std::string m_map_name;
+ std::mutex m_mutex;
};
} // namespace Common