|
9 | 9 | // Official repository: https://github.com/cppalliance/mrdox
|
10 | 10 | //
|
11 | 11 |
|
12 |
| -//===- lib/Tooling/AllTUsExecution.cpp - Execute actions on all TUs. ------===// |
13 |
| -// |
14 |
| -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
15 |
| -// See https://llvm.org/LICENSE.txt for license information. |
16 |
| -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
17 |
| -// |
18 |
| -//===----------------------------------------------------------------------===// |
19 |
| - |
20 | 12 | #include "ToolExecutor.hpp"
|
| 13 | +#include <mrdox/Support/ThreadPool.hpp> |
21 | 14 | #include <clang/Tooling/ToolExecutorPluginRegistry.h>
|
22 | 15 | #include <llvm/Support/Regex.h>
|
23 | 16 | #include <llvm/Support/ThreadPool.h>
|
@@ -132,39 +125,37 @@ execute(
|
132 | 125 |
|
133 | 126 | auto& Action = Actions.front();
|
134 | 127 |
|
| 128 | + TaskGroup taskGroup(config_.threadPool()); |
| 129 | + |
| 130 | + for (std::string File : Files) |
135 | 131 | {
|
136 |
| - llvm::ThreadPool Pool(llvm::hardware_concurrency(0)); |
137 |
| - for (std::string File : Files) |
| 132 | + taskGroup.async( |
| 133 | + [&, Path = std::move(File)]() |
138 | 134 | {
|
139 |
| - Pool.async( |
140 |
| - [&](std::string Path) |
141 |
| - { |
| 135 | + if(config_.verboseOutput) |
142 | 136 | Log("[" + std::to_string(Count()) + "/" + TotalNumStr + "] Processing file " + Path);
|
143 | 137 |
|
144 |
| - // Each thread gets an independent copy of a VFS to allow different |
145 |
| - // concurrent working directories. |
146 |
| - IntrusiveRefCntPtr<llvm::vfs::FileSystem> FS = |
147 |
| - llvm::vfs::createPhysicalFileSystem(); |
| 138 | + // Each thread gets an independent copy of a VFS to allow different |
| 139 | + // concurrent working directories. |
| 140 | + IntrusiveRefCntPtr<llvm::vfs::FileSystem> FS = |
| 141 | + llvm::vfs::createPhysicalFileSystem(); |
148 | 142 |
|
149 |
| - tooling::ClangTool Tool( Compilations, { Path }, |
150 |
| - std::make_shared<PCHContainerOperations>(), FS); |
151 |
| - Tool.appendArgumentsAdjuster(Action.second); |
152 |
| - Tool.appendArgumentsAdjuster(getDefaultArgumentsAdjusters()); |
| 143 | + tooling::ClangTool Tool( Compilations, { Path }, |
| 144 | + std::make_shared<PCHContainerOperations>(), FS); |
| 145 | + Tool.appendArgumentsAdjuster(Action.second); |
| 146 | + Tool.appendArgumentsAdjuster(getDefaultArgumentsAdjusters()); |
153 | 147 |
|
154 |
| - for (const auto& FileAndContent : OverlayFiles) |
155 |
| - Tool.mapVirtualFile(FileAndContent.first(), |
156 |
| - FileAndContent.second); |
| 148 | + for (const auto& FileAndContent : OverlayFiles) |
| 149 | + Tool.mapVirtualFile(FileAndContent.first(), |
| 150 | + FileAndContent.second); |
157 | 151 |
|
158 |
| - if (Tool.run(Action.first.get())) |
159 |
| - AppendError(llvm::Twine("Failed to run action on ") + Path + "\n"); |
160 |
| - }, |
161 |
| - File); |
162 |
| - } |
163 |
| - |
164 |
| - // Make sure all tasks have finished before resetting the working directory. |
165 |
| - Pool.wait(); |
| 152 | + if (Tool.run(Action.first.get())) |
| 153 | + AppendError(llvm::Twine("Failed to run action on ") + Path + "\n"); |
| 154 | + }); |
166 | 155 | }
|
167 | 156 |
|
| 157 | + auto errors = taskGroup.wait(); |
| 158 | + |
168 | 159 | if (!ErrorMsg.empty())
|
169 | 160 | return make_string_error(ErrorMsg);
|
170 | 161 |
|
|
0 commit comments