SharedStream DependencyOS(llvm::outs());
DependencyScanningService Service(ScanMode);
+#if LLVM_ENABLE_THREADS
unsigned NumWorkers =
NumThreads == 0 ? llvm::hardware_concurrency() : NumThreads;
+#else
+ unsigned NumWorkers = 1;
+#endif
std::vector<std::unique_ptr<DependencyScanningTool>> WorkerTools;
for (unsigned I = 0; I < NumWorkers; ++I)
WorkerTools.push_back(llvm::make_unique<DependencyScanningTool>(
llvm::outs() << "Running clang-scan-deps on " << Inputs.size()
<< " files using " << NumWorkers << " workers\n";
for (unsigned I = 0; I < NumWorkers; ++I) {
- WorkerThreads.emplace_back(
- [I, &Lock, &Index, &Inputs, &HadErrors, &WorkerTools]() {
- while (true) {
- std::string Input;
- StringRef CWD;
- // Take the next input.
- {
- std::unique_lock<std::mutex> LockGuard(Lock);
- if (Index >= Inputs.size())
- return;
- const auto &Compilation = Inputs[Index++];
- Input = Compilation.first;
- CWD = Compilation.second;
- }
- // Run the tool on it.
- if (WorkerTools[I]->runOnFile(Input, CWD))
- HadErrors = true;
- }
- });
+ auto Worker = [I, &Lock, &Index, &Inputs, &HadErrors, &WorkerTools]() {
+ while (true) {
+ std::string Input;
+ StringRef CWD;
+ // Take the next input.
+ {
+ std::unique_lock<std::mutex> LockGuard(Lock);
+ if (Index >= Inputs.size())
+ return;
+ const auto &Compilation = Inputs[Index++];
+ Input = Compilation.first;
+ CWD = Compilation.second;
+ }
+ // Run the tool on it.
+ if (WorkerTools[I]->runOnFile(Input, CWD))
+ 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();