[Lldb-commits] [lldb] DynamicLoaderDarwin load images in parallel with preload (PR #110646)

Jonas Devlieghere via lldb-commits lldb-commits at lists.llvm.org
Mon Oct 14 14:36:49 PDT 2024


================
@@ -642,26 +652,86 @@ ModuleSP DynamicLoaderDarwin::GetDYLDModule() {
 
 void DynamicLoaderDarwin::ClearDYLDModule() { m_dyld_module_wp.reset(); }
 
+template <typename InputIterator, typename ResultType>
+static std::vector<ResultType> parallel_map(
+    llvm::ThreadPoolInterface &threadPool, InputIterator first,
+    InputIterator last,
+    llvm::function_ref<ResultType(
+        const typename std::iterator_traits<InputIterator>::value_type &)>
+        transform) {
+  const auto size = std::distance(first, last);
+  std::vector<ResultType> results(size);
+  if (size > 0) {
+    llvm::ThreadPoolTaskGroup taskGroup(threadPool);
+    auto it = first;
+    for (ssize_t i = 0; i < size; ++i, ++it) {
+      taskGroup.async([&, i, it]() { results[i] = transform(*it); });
+    }
+    taskGroup.wait();
+  }
+  return results;
+}
----------------
JDevlieghere wrote:

Do we really need these `map` helpers? I would imagine you could achieve the same thing with something like this:

```
TaskGroup task_group(...);
for (...)
  if (is_parallel)
    task_group.async(lambda, args);
  else 
    lambda(args);
task_group.wait();
```

https://github.com/llvm/llvm-project/pull/110646


More information about the lldb-commits mailing list