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.
This commit is contained in:
JosJuice
2025-06-30 19:12:00 +02:00
parent 59d126d215
commit 803e6b017b
4 changed files with 84 additions and 39 deletions

View File

@ -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())
@ -61,9 +64,14 @@ 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++;
}