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

Side by Side Diff: runtime/vm/message_handler.cc

Issue 1312793004: Fix NotifyPauseOnStart and NotifyPauseOnExit dead lock (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 4 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | 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) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "vm/message_handler.h" 5 #include "vm/message_handler.h"
6 6
7 #include "vm/dart.h" 7 #include "vm/dart.h"
8 #include "vm/lockers.h" 8 #include "vm/lockers.h"
9 #include "vm/port.h" 9 #include "vm/port.h"
10 #include "vm/thread_interrupter.h" 10 #include "vm/thread_interrupter.h"
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 ASSERT(Isolate::Current() == NULL); 235 ASSERT(Isolate::Current() == NULL);
236 bool ok = true; 236 bool ok = true;
237 bool run_end_callback = false; 237 bool run_end_callback = false;
238 { 238 {
239 MonitorLocker ml(&monitor_); 239 MonitorLocker ml(&monitor_);
240 // Initialize the message handler by running its start function, 240 // Initialize the message handler by running its start function,
241 // if we have one. For an isolate, this will run the isolate's 241 // if we have one. For an isolate, this will run the isolate's
242 // main() function. 242 // main() function.
243 if (pause_on_start()) { 243 if (pause_on_start()) {
244 if (!paused_on_start_) { 244 if (!paused_on_start_) {
245 // Temporarily drop the lock when calling out to NotifyPauseOnStart.
246 // This avoids a dead lock that can occur when this message handler
247 // tries to post a message while a message is being posted to it.
248 monitor_.Exit();
245 NotifyPauseOnStart(); 249 NotifyPauseOnStart();
250 monitor_.Enter();
246 paused_on_start_ = true; 251 paused_on_start_ = true;
247 } 252 }
248 HandleMessages(false, false); 253 HandleMessages(false, false);
249 if (pause_on_start()) { 254 if (pause_on_start()) {
250 // Still paused. 255 // Still paused.
251 task_ = NULL; // No task in queue. 256 task_ = NULL; // No task in queue.
252 return; 257 return;
253 } else { 258 } else {
254 paused_on_start_ = false; 259 paused_on_start_ = false;
255 } 260 }
(...skipping 15 matching lines...) Expand all
271 } 276 }
272 task_ = NULL; // No task in queue. 277 task_ = NULL; // No task in queue.
273 278
274 if (!ok || !HasLivePorts()) { 279 if (!ok || !HasLivePorts()) {
275 if (pause_on_exit()) { 280 if (pause_on_exit()) {
276 if (!paused_on_exit_) { 281 if (!paused_on_exit_) {
277 if (FLAG_trace_service_pause_events) { 282 if (FLAG_trace_service_pause_events) {
278 OS::PrintErr("Isolate %s paused before exiting. " 283 OS::PrintErr("Isolate %s paused before exiting. "
279 "Use the Observatory to release it.\n", name()); 284 "Use the Observatory to release it.\n", name());
280 } 285 }
286 // Temporarily drop the lock when calling out to NotifyPauseOnExit.
287 // This avoids a dead lock that can occur when this message handler
288 // tries to post a message while a message is being posted to it.
289 monitor_.Exit();
281 NotifyPauseOnExit(); 290 NotifyPauseOnExit();
turnidge 2015/08/24 17:39:55 Handle this like run_end_callback as discussed off
291 monitor_.Enter();
282 paused_on_exit_ = true; 292 paused_on_exit_ = true;
283 } 293 }
284 } else { 294 } else {
285 if (FLAG_trace_isolates) { 295 if (FLAG_trace_isolates) {
286 OS::Print("[-] Stopping message handler (%s):\n" 296 OS::Print("[-] Stopping message handler (%s):\n"
287 "\thandler: %s\n", 297 "\thandler: %s\n",
288 (ok ? "no live ports" : "error"), 298 (ok ? "no live ports" : "error"),
289 name()); 299 name());
290 } 300 }
291 pool_ = NULL; 301 pool_ = NULL;
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 381
372 382
373 void MessageHandler::AcquireQueues(AcquiredQueues* acquired_queues) { 383 void MessageHandler::AcquireQueues(AcquiredQueues* acquired_queues) {
374 ASSERT(acquired_queues != NULL); 384 ASSERT(acquired_queues != NULL);
375 // No double dipping. 385 // No double dipping.
376 ASSERT(acquired_queues->handler_ == NULL); 386 ASSERT(acquired_queues->handler_ == NULL);
377 acquired_queues->Reset(this); 387 acquired_queues->Reset(this);
378 } 388 }
379 389
380 } // namespace dart 390 } // namespace dart
OLDNEW
« 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