Skip to content

Commit 535c27d

Browse files
committed
Don't lock for the duration fo GetDependentModules
1 parent 0bba5f7 commit 535c27d

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

lldb/source/Target/Target.cpp

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1613,8 +1613,28 @@ void Target::SetExecutableModule(ModuleSP &executable_sp,
16131613
added_modules.AppendIfNeeded(image_module_sp, false);
16141614
ObjectFile *objfile = image_module_sp->GetObjectFile();
16151615
if (objfile) {
1616-
std::lock_guard<std::mutex> guard(dependent_files_mutex);
1617-
objfile->GetDependentModules(dependent_files);
1616+
// Create a local copy of the dependent file list so we don't have
1617+
// to lock for the whole duration of GetDependentModules.
1618+
FileSpecList dependent_files_copy;
1619+
{
1620+
std::lock_guard<std::mutex> guard(dependent_files_mutex);
1621+
dependent_files_copy = dependent_files;
1622+
}
1623+
1624+
// Remember the size of the local copy so we can append only the
1625+
// modules that have been added by GetDependentModules.
1626+
const size_t previous_dependent_files =
1627+
dependent_files_copy.GetSize();
1628+
1629+
objfile->GetDependentModules(dependent_files_copy);
1630+
1631+
{
1632+
std::lock_guard<std::mutex> guard(dependent_files_mutex);
1633+
for (size_t i = previous_dependent_files;
1634+
i < dependent_files_copy.GetSize(); ++i)
1635+
dependent_files.AppendIfUnique(
1636+
dependent_files_copy.GetFileSpecAtIndex(i));
1637+
}
16181638
}
16191639
}
16201640
};

0 commit comments

Comments
 (0)