simgear/debug/logdelta.cxx: protect cache with a std::mutex.

This commit is contained in:
Julian Smith 2020-11-08 16:25:47 +00:00
parent a77551aa02
commit 79e1ea02ab

View File

@ -2,6 +2,7 @@
#include <iostream> #include <iostream>
#include <map> #include <map>
#include <mutex>
#include <string> #include <string>
#include <vector> #include <vector>
@ -137,6 +138,8 @@ struct logDelta
if (!function) function = ""; if (!function) function = "";
logDeltaCacheItem flf(file, line, function); logDeltaCacheItem flf(file, line, function);
std::lock_guard<std::mutex> lock( m_mutex);
auto it = m_cache.find(flf); auto it = m_cache.find(flf);
if (it == m_cache.end()) { if (it == m_cache.end()) {
@ -212,6 +215,7 @@ struct logDelta
} }
private: private:
std::mutex m_mutex;
std::map<logDeltaCacheItem, int> m_cache; std::map<logDeltaCacheItem, int> m_cache;
std::vector<logDeltaItem> m_items; std::vector<logDeltaItem> m_items;
}; };