Skip to content

Commit 3192bd6

Browse files
committed
[fix] multithreading issue with ModuleManager
1 parent c2002ae commit 3192bd6

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/moduledef.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1171,6 +1171,7 @@ struct ModuleManager::Private
11711171
std::unordered_map<std::string,ModuleList> moduleNameMap; // name->module mapping
11721172
ImportInfoMap externalImports;
11731173
HeaderInfoVector headers;
1174+
std::mutex mutex;
11741175
};
11751176

11761177
ModuleManager &ModuleManager::instance()
@@ -1188,6 +1189,7 @@ void ModuleManager::createModuleDef(const QCString &fileName,int line,int column
11881189
{
11891190
AUTO_TRACE("{}:{}: Found module name='{}' partition='{}' exported='{}'",
11901191
fileName,line,moduleName,partitionName,exported);
1192+
std::lock_guard lock(p->mutex);
11911193
ModuleDef::Type mt = exported ? ModuleDef::Type::Interface : ModuleDef::Type::Implementation;
11921194
std::unique_ptr<ModuleDef> modDef = std::make_unique<ModuleDefImpl>(fileName,line,column,moduleName,mt,partitionName);
11931195
auto mod = p->moduleFileMap.add(fileName,std::move(modDef));
@@ -1206,6 +1208,7 @@ void ModuleManager::createModuleDef(const QCString &fileName,int line,int column
12061208

12071209
void ModuleManager::clear()
12081210
{
1211+
std::lock_guard lock(p->mutex);
12091212
p->headers.clear();
12101213
p->externalImports.clear();
12111214
p->moduleNameMap.clear();
@@ -1215,6 +1218,7 @@ void ModuleManager::clear()
12151218
void ModuleManager::addHeader(const QCString &moduleFile,int line,const QCString &headerName,bool isSystem)
12161219
{
12171220
AUTO_TRACE("{}:{} headerName={} isSystem={}",moduleFile,line,headerName,isSystem);
1221+
std::lock_guard lock(p->mutex);
12181222
auto mod = p->moduleFileMap.find(moduleFile);
12191223
if (mod)
12201224
{
@@ -1232,6 +1236,7 @@ void ModuleManager::addImport(const QCString &moduleFile,int line,const QCString
12321236
{
12331237
AUTO_TRACE("{}:{} importName={},isExported={},partitionName={}",
12341238
moduleFile,line,importName,isExported,partitionName);
1239+
std::lock_guard lock(p->mutex);
12351240
auto mod = p->moduleFileMap.find(moduleFile);
12361241
if (mod) // import inside a module
12371242
{
@@ -1247,6 +1252,7 @@ void ModuleManager::addImport(const QCString &moduleFile,int line,const QCString
12471252

12481253
void ModuleManager::addClassToModule(const Entry *root,ClassDef *cd)
12491254
{
1255+
std::lock_guard lock(p->mutex);
12501256
auto mod = p->moduleFileMap.find(root->fileName);
12511257
if (mod)
12521258
{
@@ -1258,6 +1264,7 @@ void ModuleManager::addClassToModule(const Entry *root,ClassDef *cd)
12581264

12591265
void ModuleManager::addConceptToModule(const Entry *root,ConceptDef *cd)
12601266
{
1267+
std::lock_guard lock(p->mutex);
12611268
auto mod = p->moduleFileMap.find(root->fileName);
12621269
if (mod)
12631270
{
@@ -1269,6 +1276,7 @@ void ModuleManager::addConceptToModule(const Entry *root,ConceptDef *cd)
12691276

12701277
void ModuleManager::addMemberToModule(const Entry *root,MemberDef *md)
12711278
{
1279+
std::lock_guard lock(p->mutex);
12721280
auto mod = p->moduleFileMap.find(root->fileName);
12731281
if (mod && root->exported)
12741282
{
@@ -1280,6 +1288,7 @@ void ModuleManager::addMemberToModule(const Entry *root,MemberDef *md)
12801288

12811289
void ModuleManager::addTagInfo(const QCString &fileName,const QCString &tagFile,const QCString &clangId)
12821290
{
1291+
std::lock_guard lock(p->mutex);
12831292
auto mod = p->moduleFileMap.find(fileName);
12841293
if (mod)
12851294
{

0 commit comments

Comments
 (0)