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

Side by Side Diff: tools/gn/scheduler.cc

Issue 100193002: Fix GN deadlock on error handling. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | tools/gn/secondary/base/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "tools/gn/scheduler.h" 5 #include "tools/gn/scheduler.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/strings/string_number_conversions.h" 9 #include "base/strings/string_number_conversions.h"
10 #include "tools/gn/standard_out.h" 10 #include "tools/gn/standard_out.h"
(...skipping 25 matching lines...) Expand all
36 } 36 }
37 37
38 Scheduler::~Scheduler() { 38 Scheduler::~Scheduler() {
39 if (!has_been_shutdown_) 39 if (!has_been_shutdown_)
40 pool_->Shutdown(); 40 pool_->Shutdown();
41 g_scheduler = NULL; 41 g_scheduler = NULL;
42 } 42 }
43 43
44 bool Scheduler::Run() { 44 bool Scheduler::Run() {
45 runner_.Run(); 45 runner_.Run();
46 base::AutoLock lock(lock_); 46 bool local_is_failed;
47 {
48 base::AutoLock lock(lock_);
49 local_is_failed = is_failed();
50 has_been_shutdown_ = true;
51 }
52 // Don't do this inside the lock since it will block on the workers, which
53 // may be in turn waiting on the lock.
47 pool_->Shutdown(); 54 pool_->Shutdown();
48 has_been_shutdown_ = true; 55 return !local_is_failed;
49 return !is_failed();
50 } 56 }
51 57
52 void Scheduler::Log(const std::string& verb, const std::string& msg) { 58 void Scheduler::Log(const std::string& verb, const std::string& msg) {
53 if (base::MessageLoop::current() == &main_loop_) { 59 if (base::MessageLoop::current() == &main_loop_) {
54 LogOnMainThread(verb, msg); 60 LogOnMainThread(verb, msg);
55 } else { 61 } else {
56 // The run loop always joins on the sub threads, so the lifetime of this 62 // The run loop always joins on the sub threads, so the lifetime of this
57 // object outlives the invocations of this function, hence "unretained". 63 // object outlives the invocations of this function, hence "unretained".
58 main_loop_.PostTask(FROM_HERE, 64 main_loop_.PostTask(FROM_HERE,
59 base::Bind(&Scheduler::LogOnMainThread, 65 base::Bind(&Scheduler::LogOnMainThread,
60 base::Unretained(this), verb, msg)); 66 base::Unretained(this), verb, msg));
61 } 67 }
62 } 68 }
63 69
64 void Scheduler::FailWithError(const Err& err) { 70 void Scheduler::FailWithError(const Err& err) {
65 DCHECK(err.has_error()); 71 DCHECK(err.has_error());
66 { 72 {
67 base::AutoLock lock(lock_); 73 base::AutoLock lock(lock_);
68 74
69 if (is_failed_) 75 if (is_failed_ || has_been_shutdown_)
70 return; // Ignore errors once we see one. 76 return; // Ignore errors once we see one.
71 is_failed_ = true; 77 is_failed_ = true;
72 } 78 }
73 79
74 if (base::MessageLoop::current() == &main_loop_) { 80 if (base::MessageLoop::current() == &main_loop_) {
75 FailWithErrorOnMainThread(err); 81 FailWithErrorOnMainThread(err);
76 } else { 82 } else {
77 // The run loop always joins on the sub threads, so the lifetime of this 83 // The run loop always joins on the sub threads, so the lifetime of this
78 // object outlives the invocations of this function, hence "unretained". 84 // object outlives the invocations of this function, hence "unretained".
79 main_loop_.PostTask(FROM_HERE, 85 main_loop_.PostTask(FROM_HERE,
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 void Scheduler::DoWork(const base::Closure& closure) { 136 void Scheduler::DoWork(const base::Closure& closure) {
131 closure.Run(); 137 closure.Run();
132 DecrementWorkCount(); 138 DecrementWorkCount();
133 } 139 }
134 140
135 void Scheduler::OnComplete() { 141 void Scheduler::OnComplete() {
136 // Should be called on the main thread. 142 // Should be called on the main thread.
137 DCHECK(base::MessageLoop::current() == main_loop()); 143 DCHECK(base::MessageLoop::current() == main_loop());
138 runner_.Quit(); 144 runner_.Quit();
139 } 145 }
OLDNEW
« no previous file with comments | « no previous file | tools/gn/secondary/base/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698