From 09e5bd29bf6eb33c4d975f0339c419e207843b31 Mon Sep 17 00:00:00 2001 From: Chris Cannam Date: Thu, 11 Mar 2021 16:14:40 +0000 Subject: [PATCH] Protect profiler map with a mutex --- src/base/Profiler.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/base/Profiler.cpp b/src/base/Profiler.cpp index b1305b3..d96b571 100644 --- a/src/base/Profiler.cpp +++ b/src/base/Profiler.cpp @@ -23,6 +23,8 @@ #include "Profiler.h" +#include "system/Thread.h" + #include #include #include @@ -45,9 +47,13 @@ Profiler::m_profiles; Profiler::WorstCallMap Profiler::m_worstCalls; +static Mutex profileMutex; + void Profiler::add(const char *id, float ms) { + profileMutex.lock(); + ProfileMap::iterator pmi = m_profiles.find(id); if (pmi != m_profiles.end()) { ++pmi->second.first; @@ -62,6 +68,8 @@ Profiler::add(const char *id, float ms) } else { m_worstCalls[id] = ms; } + + profileMutex.unlock(); } void @@ -74,6 +82,8 @@ Profiler::dump() std::string Profiler::getReport() { + profileMutex.lock(); + static const int buflen = 256; char buffer[buflen]; std::string report; @@ -167,6 +177,8 @@ Profiler::getReport() report += buffer; } + profileMutex.unlock(); + return report; }