Skip to content

Commit 3ffa688

Browse files
committed
clang-scan-deps: do not spawn threads when LLVM_ENABLE_THREADS is disabled
llvm-svn: 368640
1 parent f4446f1 commit 3ffa688

File tree

2 files changed

+28
-20
lines changed

2 files changed

+28
-20
lines changed

clang/test/ClangScanDeps/regular_cdb.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// REQUIRES: thread_support
21
// RUN: rm -rf %t.dir
32
// RUN: rm -rf %t.cdb
43
// RUN: mkdir -p %t.dir

clang/tools/clang-scan-deps/ClangScanDeps.cpp

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,12 @@ int main(int argc, const char **argv) {
154154
SharedStream DependencyOS(llvm::outs());
155155

156156
DependencyScanningService Service(ScanMode);
157+
#if LLVM_ENABLE_THREADS
157158
unsigned NumWorkers =
158159
NumThreads == 0 ? llvm::hardware_concurrency() : NumThreads;
160+
#else
161+
unsigned NumWorkers = 1;
162+
#endif
159163
std::vector<std::unique_ptr<DependencyScanningTool>> WorkerTools;
160164
for (unsigned I = 0; I < NumWorkers; ++I)
161165
WorkerTools.push_back(llvm::make_unique<DependencyScanningTool>(
@@ -169,25 +173,30 @@ int main(int argc, const char **argv) {
169173
llvm::outs() << "Running clang-scan-deps on " << Inputs.size()
170174
<< " files using " << NumWorkers << " workers\n";
171175
for (unsigned I = 0; I < NumWorkers; ++I) {
172-
WorkerThreads.emplace_back(
173-
[I, &Lock, &Index, &Inputs, &HadErrors, &WorkerTools]() {
174-
while (true) {
175-
std::string Input;
176-
StringRef CWD;
177-
// Take the next input.
178-
{
179-
std::unique_lock<std::mutex> LockGuard(Lock);
180-
if (Index >= Inputs.size())
181-
return;
182-
const auto &Compilation = Inputs[Index++];
183-
Input = Compilation.first;
184-
CWD = Compilation.second;
185-
}
186-
// Run the tool on it.
187-
if (WorkerTools[I]->runOnFile(Input, CWD))
188-
HadErrors = true;
189-
}
190-
});
176+
auto Worker = [I, &Lock, &Index, &Inputs, &HadErrors, &WorkerTools]() {
177+
while (true) {
178+
std::string Input;
179+
StringRef CWD;
180+
// Take the next input.
181+
{
182+
std::unique_lock<std::mutex> LockGuard(Lock);
183+
if (Index >= Inputs.size())
184+
return;
185+
const auto &Compilation = Inputs[Index++];
186+
Input = Compilation.first;
187+
CWD = Compilation.second;
188+
}
189+
// Run the tool on it.
190+
if (WorkerTools[I]->runOnFile(Input, CWD))
191+
HadErrors = true;
192+
}
193+
};
194+
#if LLVM_ENABLE_THREADS
195+
WorkerThreads.emplace_back(std::move(Worker));
196+
#else
197+
// Run the worker without spawning a thread when threads are disabled.
198+
Worker();
199+
#endif
191200
}
192201
for (auto &W : WorkerThreads)
193202
W.join();

0 commit comments

Comments
 (0)