[PATCH] D145101: [clang][deps] NFC: Simplify worker loop
Jan Svoboda via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Mar 2 13:50:26 PST 2023
This revision was automatically updated to reflect the committed changes.
Closed by commit rG9679075a1ae6: [clang][deps] NFC: Simplify worker loop (authored by jansvoboda11).
Changed prior to commit:
https://reviews.llvm.org/D145101?vs=501616&id=501969#toc
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D145101/new/
https://reviews.llvm.org/D145101
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
@@ -783,8 +783,15 @@
std::atomic<bool> HadErrors(false);
std::optional<FullDeps> FD;
P1689Deps PD;
+
std::mutex Lock;
size_t Index = 0;
+ auto GetNextInputIndex = [&]() -> std::optional<size_t> {
+ std::unique_lock<std::mutex> LockGuard(Lock);
+ if (Index < Inputs.size())
+ return Index++;
+ return {};
+ };
if (Format == ScanningOutputFormat::Full)
FD.emplace(ModuleName.empty() ? Inputs.size() : 0);
@@ -794,24 +801,14 @@
<< " files using " << Pool.getThreadCount() << " workers\n";
}
for (unsigned I = 0; I < Pool.getThreadCount(); ++I) {
- Pool.async([I, &Lock, &Index, &Inputs, &HadErrors, &FD, &PD, &WorkerTools,
- &DependencyOS, &Errs]() {
+ Pool.async([&, I]() {
llvm::StringSet<> AlreadySeenModules;
- while (true) {
- const tooling::CompileCommand *Input;
- std::string Filename;
- std::string CWD;
- size_t LocalIndex;
- // Take the next input.
- {
- std::unique_lock<std::mutex> LockGuard(Lock);
- if (Index >= Inputs.size())
- return;
- LocalIndex = Index;
- Input = &Inputs[Index++];
- Filename = std::move(Input->Filename);
- CWD = std::move(Input->Directory);
- }
+ while (auto MaybeInputIndex = GetNextInputIndex()) {
+ size_t LocalIndex = *MaybeInputIndex;
+ const tooling::CompileCommand *Input = &Inputs[LocalIndex];
+ std::string Filename = std::move(Input->Filename);
+ std::string CWD = std::move(Input->Directory);
+
std::optional<StringRef> MaybeModuleName;
if (!ModuleName.empty())
MaybeModuleName = ModuleName;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D145101.501969.patch
Type: text/x-patch
Size: 1934 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230302/1715482d/attachment-0001.bin>
More information about the cfe-commits
mailing list