Skip to content

Commit d1b0340

Browse files
committed
chore: ToolExecutor uses Config
1 parent f5db91d commit d1b0340

File tree

1 file changed

+23
-32
lines changed

1 file changed

+23
-32
lines changed

source/AST/ToolExecutor.cpp

+23-32
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,8 @@
99
// Official repository: https://github.com/cppalliance/mrdox
1010
//
1111

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-
2012
#include "ToolExecutor.hpp"
13+
#include <mrdox/Support/ThreadPool.hpp>
2114
#include <clang/Tooling/ToolExecutorPluginRegistry.h>
2215
#include <llvm/Support/Regex.h>
2316
#include <llvm/Support/ThreadPool.h>
@@ -132,39 +125,37 @@ execute(
132125

133126
auto& Action = Actions.front();
134127

128+
TaskGroup taskGroup(config_.threadPool());
129+
130+
for (std::string File : Files)
135131
{
136-
llvm::ThreadPool Pool(llvm::hardware_concurrency(0));
137-
for (std::string File : Files)
132+
taskGroup.async(
133+
[&, Path = std::move(File)]()
138134
{
139-
Pool.async(
140-
[&](std::string Path)
141-
{
135+
if(config_.verboseOutput)
142136
Log("[" + std::to_string(Count()) + "/" + TotalNumStr + "] Processing file " + Path);
143137

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();
148142

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());
153147

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);
157151

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+
});
166155
}
167156

157+
auto errors = taskGroup.wait();
158+
168159
if (!ErrorMsg.empty())
169160
return make_string_error(ErrorMsg);
170161

0 commit comments

Comments
 (0)