Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(117)

Unified Diff: tools/gn/setup.cc

Issue 2617253002: Fix a GN race condition. (Closed)
Patch Set: Fix other race condition. Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/gn/setup.cc
diff --git a/tools/gn/setup.cc b/tools/gn/setup.cc
index 8a433bcdbb1cacf67fd0e96bdbaf5f5bee9dc360..06062e9e5ab40629289e5e0341407bfc0febd8af 100644
--- a/tools/gn/setup.cc
+++ b/tools/gn/setup.cc
@@ -137,15 +137,31 @@ base::FilePath FindDotFile(const base::FilePath& current_dir) {
return FindDotFile(up_one_dir);
}
+void ForwardItemDefinedToBuilderInMainThread(
+ Builder* builder_call_on_main_thread_only,
+ std::unique_ptr<Item> item) {
+ builder_call_on_main_thread_only->ItemDefined(std::move(item));
+
+ // Pair to the Increment in ItemDefinedCallback.
+ g_scheduler->DecrementWorkCount();
+}
+
// Called on any thread. Post the item to the builder on the main thread.
void ItemDefinedCallback(
scoped_refptr<base::SingleThreadTaskRunner> task_runner,
Builder* builder_call_on_main_thread_only,
std::unique_ptr<Item> item) {
DCHECK(item);
+
+ // Increment the work count for the duration of defining the item with the
+ // builder. Otherwise finishing this callback will race finishing loading
+ // files. If there is no other pending work at any point in the middle of
+ // this call completing on the main thread, the 'Complete' function will
+ // be signaled and we'll stop running with an incomplete build.
+ g_scheduler->IncrementWorkCount();
task_runner->PostTask(
FROM_HERE,
- base::Bind(&Builder::ItemDefined,
+ base::Bind(&ForwardItemDefinedToBuilderInMainThread,
base::Unretained(builder_call_on_main_thread_only),
base::Passed(&item)));
}
@@ -321,11 +337,11 @@ SourceFile Setup::GetBuildArgFile() const {
}
void Setup::RunPreMessageLoop() {
- // Load the root build file.
- loader_->Load(root_build_file_, LocationRange(), Label());
-
// Will be decremented with the loader is drained.
g_scheduler->IncrementWorkCount();
+
+ // Load the root build file.
+ loader_->Load(root_build_file_, LocationRange(), Label());
}
bool Setup::RunPostMessageLoop() {
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698