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

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 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 bool MessageHandler::HasOOBMessages() { 228 bool MessageHandler::HasOOBMessages() {
229 MonitorLocker ml(&monitor_); 229 MonitorLocker ml(&monitor_);
230 return !oob_queue_->IsEmpty(); 230 return !oob_queue_->IsEmpty();
231 } 231 }
232 232
233 233
234 void MessageHandler::TaskCallback() { 234 void MessageHandler::TaskCallback() {
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 bool notify_paused_on_exit = false;
238 { 239 {
239 MonitorLocker ml(&monitor_); 240 MonitorLocker ml(&monitor_);
240 // Initialize the message handler by running its start function, 241 // Initialize the message handler by running its start function,
241 // if we have one. For an isolate, this will run the isolate's 242 // if we have one. For an isolate, this will run the isolate's
242 // main() function. 243 // main() function.
243 if (pause_on_start()) { 244 if (pause_on_start()) {
244 if (!paused_on_start_) { 245 if (!paused_on_start_) {
246 // Temporarily drop the lock when calling out to NotifyPauseOnStart.
247 // This avoids a dead lock that can occur when this message handler
248 // tries to post a message while a message is being posted to it.
249 monitor_.Exit();
245 NotifyPauseOnStart(); 250 NotifyPauseOnStart();
251 monitor_.Enter();
246 paused_on_start_ = true; 252 paused_on_start_ = true;
247 } 253 }
248 HandleMessages(false, false); 254 HandleMessages(false, false);
249 if (pause_on_start()) { 255 if (pause_on_start()) {
250 // Still paused. 256 // Still paused.
251 task_ = NULL; // No task in queue. 257 task_ = NULL; // No task in queue.
252 return; 258 return;
253 } else { 259 } else {
254 paused_on_start_ = false; 260 paused_on_start_ = false;
255 } 261 }
(...skipping 15 matching lines...) Expand all
271 } 277 }
272 task_ = NULL; // No task in queue. 278 task_ = NULL; // No task in queue.
273 279
274 if (!ok || !HasLivePorts()) { 280 if (!ok || !HasLivePorts()) {
275 if (pause_on_exit()) { 281 if (pause_on_exit()) {
276 if (!paused_on_exit_) { 282 if (!paused_on_exit_) {
277 if (FLAG_trace_service_pause_events) { 283 if (FLAG_trace_service_pause_events) {
278 OS::PrintErr("Isolate %s paused before exiting. " 284 OS::PrintErr("Isolate %s paused before exiting. "
279 "Use the Observatory to release it.\n", name()); 285 "Use the Observatory to release it.\n", name());
280 } 286 }
281 NotifyPauseOnExit(); 287 notify_paused_on_exit = true;
282 paused_on_exit_ = true; 288 paused_on_exit_ = true;
283 } 289 }
284 } else { 290 } else {
285 if (FLAG_trace_isolates) { 291 if (FLAG_trace_isolates) {
286 OS::Print("[-] Stopping message handler (%s):\n" 292 OS::Print("[-] Stopping message handler (%s):\n"
287 "\thandler: %s\n", 293 "\thandler: %s\n",
288 (ok ? "no live ports" : "error"), 294 (ok ? "no live ports" : "error"),
289 name()); 295 name());
290 } 296 }
291 pool_ = NULL; 297 pool_ = NULL;
292 run_end_callback = true; 298 run_end_callback = true;
293 paused_on_exit_ = false; 299 paused_on_exit_ = false;
294 } 300 }
295 } 301 }
296 } 302 }
303 // At this point we no longer hold the message handler lock.
304 if (notify_paused_on_exit) {
305 NotifyPauseOnExit();
306 }
297 if (run_end_callback && end_callback_ != NULL) { 307 if (run_end_callback && end_callback_ != NULL) {
298 end_callback_(callback_data_); 308 end_callback_(callback_data_);
299 // The handler may have been deleted after this point. 309 // The handler may have been deleted after this point.
300 } 310 }
301 } 311 }
302 312
303 313
304 void MessageHandler::ClosePort(Dart_Port port) { 314 void MessageHandler::ClosePort(Dart_Port port) {
305 MonitorLocker ml(&monitor_); 315 MonitorLocker ml(&monitor_);
306 if (FLAG_trace_isolates) { 316 if (FLAG_trace_isolates) {
(...skipping 64 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