[Lldb-commits] [lldb] [lldb] Create dependent modules in parallel (PR #114507)
Jonas Devlieghere via lldb-commits
lldb-commits at lists.llvm.org
Sat Nov 2 09:37:53 PDT 2024
================
@@ -1608,9 +1612,48 @@ void Target::SetExecutableModule(ModuleSP &executable_sp,
if (image_module_sp) {
added_modules.AppendIfNeeded(image_module_sp, false);
ObjectFile *objfile = image_module_sp->GetObjectFile();
- if (objfile)
- objfile->GetDependentModules(dependent_files);
+ if (objfile) {
+ // Create a local copy of the dependent file list so we don't have
+ // to lock for the whole duration of GetDependentModules.
+ FileSpecList dependent_files_copy;
+ {
+ std::lock_guard<std::mutex> guard(dependent_files_mutex);
+ dependent_files_copy = dependent_files;
+ }
+
+ // Remember the size of the local copy so we can append only the
+ // modules that have been added by GetDependentModules.
+ const size_t previous_dependent_files =
+ dependent_files_copy.GetSize();
+
+ objfile->GetDependentModules(dependent_files_copy);
+
+ {
+ std::lock_guard<std::mutex> guard(dependent_files_mutex);
+ for (size_t i = previous_dependent_files;
+ i < dependent_files_copy.GetSize(); ++i)
+ dependent_files.AppendIfUnique(
+ dependent_files_copy.GetFileSpecAtIndex(i));
+ }
+ }
+ }
+ };
+
+ executable_objfile->GetDependentModules(dependent_files);
+
+ llvm::ThreadPoolTaskGroup task_group(Debugger::GetThreadPool());
+ for (uint32_t i = 0; i < dependent_files.GetSize(); i++) {
+ // Process all currently known dependencies in parallel in the innermost
+ // loop. This may create newly discovered dependencies to be appended to
+ // dependent_files. We'll deal with these files during the next
+ // iteration of the outermost loop.
+ {
+ std::lock_guard<std::mutex> guard(dependent_files_mutex);
+ for (; i < dependent_files.GetSize(); i++)
+ task_group.async(GetDependentModules,
----------------
JDevlieghere wrote:
It doesn't, but if that becomes a problem we can do the same trick that Jason suggested and iterate over a copy of the list here. For now that seems unnecessary but hopefully someone will see this comment if that ever changes :-)
https://github.com/llvm/llvm-project/pull/114507
More information about the lldb-commits
mailing list