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 #include @@ -490,6 +491,7 @@ #else unsigned NumWorkers = 1; #endif + llvm::ThreadPool Pool(NumWorkers); std::vector> WorkerTools; for (unsigned I = 0; I < NumWorkers; ++I) WorkerTools.push_back(std::make_unique(Service)); @@ -499,7 +501,6 @@ AdjustingCompilations->getAllCompileCommands()) Inputs.emplace_back(Cmd); - std::vector WorkerThreads; std::atomic 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());