[PATCH] D74569: [clang-scan-deps] Switch to using a ThreadPool
Alexandre Ganea via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Feb 13 10:33:45 PST 2020
aganea created this revision.
aganea added reviewers: arphaman, dexonsmith, Bigcheese.
Herald added subscribers: llvm-commits, cfe-commits, tschuett, hiraditya.
Herald added projects: clang, LLVM.
aganea updated this revision to Diff 244475.
This was already reviewed as part of D71775 <https://reviews.llvm.org/D71775>, but I wanted:
1. Make sure you were fine with this change.
2. Split out the unrelated bits from D71775 <https://reviews.llvm.org/D71775> .
Tested with and without LLVM_ENABLE_THREADS.
https://reviews.llvm.org/D74569
Files:
clang/tools/clang-scan-deps/ClangScanDeps.cpp
Index: clang/tools/clang-scan-deps/ClangScanDeps.cpp
===================================================================
--- clang/tools/clang-scan-deps/ClangScanDeps.cpp
+++ 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 @@
#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 @@
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 @@
<< " 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 @@
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());
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D74569.244475.patch
Type: text/x-patch
Size: 1906 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200213/31266aaa/attachment.bin>
More information about the cfe-commits
mailing list