AutoTest: Guard simultaneous access to header cache

It is accessed from multiple threads at once. Guard with mutex to avoid
crashes.

Amends 64ce2a6f43

Change-Id: I5048e5fcdb27b2492656b302775378829b6da013
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
Eike Ziller
2021-07-07 10:33:28 +02:00
parent 434c33f4ee
commit 0df677f7ac

View File

@@ -37,6 +37,7 @@ namespace Autotest {
using LookupInfo = QPair<QString, QString>; using LookupInfo = QPair<QString, QString>;
static QHash<LookupInfo, bool> s_pchLookupCache; static QHash<LookupInfo, bool> s_pchLookupCache;
Q_GLOBAL_STATIC(QMutex, s_cacheMutex);
CppParser::CppParser(ITestFramework *framework) CppParser::CppParser(ITestFramework *framework)
: ITestParser(framework) : ITestParser(framework)
@@ -96,6 +97,7 @@ bool precompiledHeaderContains(const CPlusPlus::Snapshot &snapshot,
} }
return it.value(); return it.value();
}; };
QMutexLocker l(s_cacheMutex());
return Utils::anyOf(precompiledHeaders, headerContains); return Utils::anyOf(precompiledHeaders, headerContains);
} }
@@ -127,6 +129,7 @@ void CppParser::release()
{ {
m_cppSnapshot = CPlusPlus::Snapshot(); m_cppSnapshot = CPlusPlus::Snapshot();
m_workingCopy = CppTools::WorkingCopy(); m_workingCopy = CppTools::WorkingCopy();
QMutexLocker l(s_cacheMutex());
s_pchLookupCache.clear(); s_pchLookupCache.clear();
} }