@@ -154,8 +154,12 @@ int main(int argc, const char **argv) {
154
154
SharedStream DependencyOS (llvm::outs ());
155
155
156
156
DependencyScanningService Service (ScanMode);
157
+ #if LLVM_ENABLE_THREADS
157
158
unsigned NumWorkers =
158
159
NumThreads == 0 ? llvm::hardware_concurrency () : NumThreads;
160
+ #else
161
+ unsigned NumWorkers = 1 ;
162
+ #endif
159
163
std::vector<std::unique_ptr<DependencyScanningTool>> WorkerTools;
160
164
for (unsigned I = 0 ; I < NumWorkers; ++I)
161
165
WorkerTools.push_back (llvm::make_unique<DependencyScanningTool>(
@@ -169,25 +173,30 @@ int main(int argc, const char **argv) {
169
173
llvm::outs () << " Running clang-scan-deps on " << Inputs.size ()
170
174
<< " files using " << NumWorkers << " workers\n " ;
171
175
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
191
200
}
192
201
for (auto &W : WorkerThreads)
193
202
W.join ();
0 commit comments