[clang] d9049e8 - [clang-scan-deps] Switch to using a ThreadPool
Alexandre Ganea via cfe-commits
cfe-commits at lists.llvm.org
Fri Feb 14 07:25:59 PST 2020
Author: Alexandre Ganea
Date: 2020-02-14T10:24:22-05:00
New Revision: d9049e871f309199a3d8fd7d3c0f76c86af9db91
URL: https://github.com/llvm/llvm-project/commit/d9049e871f309199a3d8fd7d3c0f76c86af9db91
DIFF: https://github.com/llvm/llvm-project/commit/d9049e871f309199a3d8fd7d3c0f76c86af9db91.diff
LOG: [clang-scan-deps] Switch to using a ThreadPool
Use a ThreadPool instead of plain std::threads in clang-scan-deps.
This is needed to further support https://reviews.llvm.org/D71775.
Differential Revision: https://reviews.llvm.org/D74569
Added:
Modified:
clang/tools/clang-scan-deps/ClangScanDeps.cpp
Removed:
################################################################################
diff --git a/clang/tools/clang-scan-deps/ClangScanDeps.cpp b/clang/tools/clang-scan-deps/ClangScanDeps.cpp
index 50788cb7cf8b..c499048fdb52 100644
--- a/clang/tools/clang-scan-deps/ClangScanDeps.cpp
+++ b/clang/tools/clang-scan-deps/ClangScanDeps.cpp
@@ -18,6 +18,7 @@
#include "llvm/Support/JSON.h"
#include "llvm/Support/Program.h"
#include "llvm/Support/Signals.h"
+#include "llvm/Support/ThreadPool.h"
#include "llvm/Support/Threading.h"
#include <mutex>
#include <thread>
@@ -490,6 +491,7 @@ int main(int argc, const char **argv) {
#else
unsigned NumWorkers = 1;
#endif
+ llvm::ThreadPool Pool(NumWorkers);
std::vector<std::unique_ptr<DependencyScanningTool>> WorkerTools;
for (unsigned I = 0; I < NumWorkers; ++I)
WorkerTools.push_back(std::make_unique<DependencyScanningTool>(Service));
@@ -499,7 +501,6 @@ int main(int argc, const char **argv) {
AdjustingCompilations->getAllCompileCommands())
Inputs.emplace_back(Cmd);
- std::vector<std::thread> WorkerThreads;
std::atomic<bool> HadErrors(false);
FullDeps FD;
std::mutex Lock;
@@ -510,8 +511,8 @@ int main(int argc, const char **argv) {
<< " files using " << NumWorkers << " workers\n";
}
for (unsigned I = 0; I < NumWorkers; ++I) {
- auto Worker = [I, &Lock, &Index, &Inputs, &HadErrors, &FD, &WorkerTools,
- &DependencyOS, &Errs]() {
+ Pool.async([I, &Lock, &Index, &Inputs, &HadErrors, &FD, &WorkerTools,
+ &DependencyOS, &Errs]() {
llvm::StringSet<> AlreadySeenModules;
while (true) {
const SingleCommandCompilationDatabase *Input;
@@ -543,16 +544,9 @@ int main(int argc, const char **argv) {
HadErrors = true;
}
}
- };
-#if LLVM_ENABLE_THREADS
- WorkerThreads.emplace_back(std::move(Worker));
-#else
- // Run the worker without spawning a thread when threads are disabled.
- Worker();
-#endif
+ });
}
- for (auto &W : WorkerThreads)
- W.join();
+ Pool.wait();
if (Format == ScanningOutputFormat::Full)
FD.printFullOutput(llvm::outs());
More information about the cfe-commits
mailing list