OLD | NEW |
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/object.h" | 9 #include "vm/object.h" |
10 #include "vm/object_store.h" | 10 #include "vm/object_store.h" |
11 #include "vm/os.h" | 11 #include "vm/os.h" |
12 #include "vm/port.h" | 12 #include "vm/port.h" |
13 #include "vm/thread_interrupter.h" | 13 #include "vm/thread_interrupter.h" |
14 | 14 |
15 | |
16 namespace dart { | 15 namespace dart { |
17 | 16 |
18 DECLARE_FLAG(bool, trace_service_pause_events); | 17 DECLARE_FLAG(bool, trace_service_pause_events); |
19 | 18 |
20 class MessageHandlerTask : public ThreadPool::Task { | 19 class MessageHandlerTask : public ThreadPool::Task { |
21 public: | 20 public: |
22 explicit MessageHandlerTask(MessageHandler* handler) : handler_(handler) { | 21 explicit MessageHandlerTask(MessageHandler* handler) : handler_(handler) { |
23 ASSERT(handler != NULL); | 22 ASSERT(handler != NULL); |
24 } | 23 } |
25 | 24 |
26 virtual void Run() { | 25 virtual void Run() { |
27 ASSERT(handler_ != NULL); | 26 ASSERT(handler_ != NULL); |
28 handler_->TaskCallback(); | 27 handler_->TaskCallback(); |
29 } | 28 } |
30 | 29 |
31 private: | 30 private: |
32 MessageHandler* handler_; | 31 MessageHandler* handler_; |
33 | 32 |
34 DISALLOW_COPY_AND_ASSIGN(MessageHandlerTask); | 33 DISALLOW_COPY_AND_ASSIGN(MessageHandlerTask); |
35 }; | 34 }; |
36 | 35 |
37 | |
38 // static | 36 // static |
39 const char* MessageHandler::MessageStatusString(MessageStatus status) { | 37 const char* MessageHandler::MessageStatusString(MessageStatus status) { |
40 switch (status) { | 38 switch (status) { |
41 case kOK: | 39 case kOK: |
42 return "OK"; | 40 return "OK"; |
43 case kError: | 41 case kError: |
44 return "Error"; | 42 return "Error"; |
45 case kRestart: | 43 case kRestart: |
46 return "Restart"; | 44 return "Restart"; |
47 case kShutdown: | 45 case kShutdown: |
48 return "Shutdown"; | 46 return "Shutdown"; |
49 default: | 47 default: |
50 UNREACHABLE(); | 48 UNREACHABLE(); |
51 return "Illegal"; | 49 return "Illegal"; |
52 } | 50 } |
53 } | 51 } |
54 | 52 |
55 | |
56 MessageHandler::MessageHandler() | 53 MessageHandler::MessageHandler() |
57 : queue_(new MessageQueue()), | 54 : queue_(new MessageQueue()), |
58 oob_queue_(new MessageQueue()), | 55 oob_queue_(new MessageQueue()), |
59 oob_message_handling_allowed_(true), | 56 oob_message_handling_allowed_(true), |
60 live_ports_(0), | 57 live_ports_(0), |
61 paused_(0), | 58 paused_(0), |
62 should_pause_on_start_(false), | 59 should_pause_on_start_(false), |
63 should_pause_on_exit_(false), | 60 should_pause_on_exit_(false), |
64 is_paused_on_start_(false), | 61 is_paused_on_start_(false), |
65 is_paused_on_exit_(false), | 62 is_paused_on_exit_(false), |
66 delete_me_(false), | 63 delete_me_(false), |
67 paused_timestamp_(-1), | 64 paused_timestamp_(-1), |
68 pool_(NULL), | 65 pool_(NULL), |
69 task_(NULL), | 66 task_(NULL), |
70 start_callback_(NULL), | 67 start_callback_(NULL), |
71 end_callback_(NULL), | 68 end_callback_(NULL), |
72 callback_data_(0) { | 69 callback_data_(0) { |
73 ASSERT(queue_ != NULL); | 70 ASSERT(queue_ != NULL); |
74 ASSERT(oob_queue_ != NULL); | 71 ASSERT(oob_queue_ != NULL); |
75 } | 72 } |
76 | 73 |
77 | |
78 MessageHandler::~MessageHandler() { | 74 MessageHandler::~MessageHandler() { |
79 delete queue_; | 75 delete queue_; |
80 delete oob_queue_; | 76 delete oob_queue_; |
81 queue_ = NULL; | 77 queue_ = NULL; |
82 oob_queue_ = NULL; | 78 oob_queue_ = NULL; |
83 pool_ = NULL; | 79 pool_ = NULL; |
84 task_ = NULL; | 80 task_ = NULL; |
85 } | 81 } |
86 | 82 |
87 | |
88 const char* MessageHandler::name() const { | 83 const char* MessageHandler::name() const { |
89 return "<unnamed>"; | 84 return "<unnamed>"; |
90 } | 85 } |
91 | 86 |
92 | |
93 #if defined(DEBUG) | 87 #if defined(DEBUG) |
94 void MessageHandler::CheckAccess() { | 88 void MessageHandler::CheckAccess() { |
95 // By default there is no checking. | 89 // By default there is no checking. |
96 } | 90 } |
97 #endif | 91 #endif |
98 | 92 |
99 | |
100 void MessageHandler::MessageNotify(Message::Priority priority) { | 93 void MessageHandler::MessageNotify(Message::Priority priority) { |
101 // By default, there is no custom message notification. | 94 // By default, there is no custom message notification. |
102 } | 95 } |
103 | 96 |
104 | |
105 void MessageHandler::Run(ThreadPool* pool, | 97 void MessageHandler::Run(ThreadPool* pool, |
106 StartCallback start_callback, | 98 StartCallback start_callback, |
107 EndCallback end_callback, | 99 EndCallback end_callback, |
108 CallbackData data) { | 100 CallbackData data) { |
109 bool task_running; | 101 bool task_running; |
110 MonitorLocker ml(&monitor_); | 102 MonitorLocker ml(&monitor_); |
111 if (FLAG_trace_isolates) { | 103 if (FLAG_trace_isolates) { |
112 OS::Print( | 104 OS::Print( |
113 "[+] Starting message handler:\n" | 105 "[+] Starting message handler:\n" |
114 "\thandler: %s\n", | 106 "\thandler: %s\n", |
115 name()); | 107 name()); |
116 } | 108 } |
117 ASSERT(pool_ == NULL); | 109 ASSERT(pool_ == NULL); |
118 ASSERT(!delete_me_); | 110 ASSERT(!delete_me_); |
119 pool_ = pool; | 111 pool_ = pool; |
120 start_callback_ = start_callback; | 112 start_callback_ = start_callback; |
121 end_callback_ = end_callback; | 113 end_callback_ = end_callback; |
122 callback_data_ = data; | 114 callback_data_ = data; |
123 task_ = new MessageHandlerTask(this); | 115 task_ = new MessageHandlerTask(this); |
124 task_running = pool_->Run(task_); | 116 task_running = pool_->Run(task_); |
125 ASSERT(task_running); | 117 ASSERT(task_running); |
126 } | 118 } |
127 | 119 |
128 | |
129 void MessageHandler::PostMessage(Message* message, bool before_events) { | 120 void MessageHandler::PostMessage(Message* message, bool before_events) { |
130 Message::Priority saved_priority; | 121 Message::Priority saved_priority; |
131 bool task_running = true; | 122 bool task_running = true; |
132 { | 123 { |
133 MonitorLocker ml(&monitor_); | 124 MonitorLocker ml(&monitor_); |
134 if (FLAG_trace_isolates) { | 125 if (FLAG_trace_isolates) { |
135 const char* source_name = "<native code>"; | 126 const char* source_name = "<native code>"; |
136 Isolate* source_isolate = Isolate::Current(); | 127 Isolate* source_isolate = Isolate::Current(); |
137 if (source_isolate) { | 128 if (source_isolate) { |
138 source_name = source_isolate->name(); | 129 source_name = source_isolate->name(); |
(...skipping 21 matching lines...) Expand all Loading... |
160 task_ = new MessageHandlerTask(this); | 151 task_ = new MessageHandlerTask(this); |
161 task_running = pool_->Run(task_); | 152 task_running = pool_->Run(task_); |
162 } | 153 } |
163 } | 154 } |
164 ASSERT(task_running); | 155 ASSERT(task_running); |
165 | 156 |
166 // Invoke any custom message notification. | 157 // Invoke any custom message notification. |
167 MessageNotify(saved_priority); | 158 MessageNotify(saved_priority); |
168 } | 159 } |
169 | 160 |
170 | |
171 Message* MessageHandler::DequeueMessage(Message::Priority min_priority) { | 161 Message* MessageHandler::DequeueMessage(Message::Priority min_priority) { |
172 // TODO(turnidge): Add assert that monitor_ is held here. | 162 // TODO(turnidge): Add assert that monitor_ is held here. |
173 Message* message = oob_queue_->Dequeue(); | 163 Message* message = oob_queue_->Dequeue(); |
174 if ((message == NULL) && (min_priority < Message::kOOBPriority)) { | 164 if ((message == NULL) && (min_priority < Message::kOOBPriority)) { |
175 message = queue_->Dequeue(); | 165 message = queue_->Dequeue(); |
176 } | 166 } |
177 return message; | 167 return message; |
178 } | 168 } |
179 | 169 |
180 | |
181 void MessageHandler::ClearOOBQueue() { | 170 void MessageHandler::ClearOOBQueue() { |
182 oob_queue_->Clear(); | 171 oob_queue_->Clear(); |
183 } | 172 } |
184 | 173 |
185 | |
186 MessageHandler::MessageStatus MessageHandler::HandleMessages( | 174 MessageHandler::MessageStatus MessageHandler::HandleMessages( |
187 MonitorLocker* ml, | 175 MonitorLocker* ml, |
188 bool allow_normal_messages, | 176 bool allow_normal_messages, |
189 bool allow_multiple_normal_messages) { | 177 bool allow_multiple_normal_messages) { |
190 // TODO(turnidge): Add assert that monitor_ is held here. | 178 // TODO(turnidge): Add assert that monitor_ is held here. |
191 | 179 |
192 // If isolate() returns NULL StartIsolateScope does nothing. | 180 // If isolate() returns NULL StartIsolateScope does nothing. |
193 StartIsolateScope start_isolate(isolate()); | 181 StartIsolateScope start_isolate(isolate()); |
194 | 182 |
195 MessageStatus max_status = kOK; | 183 MessageStatus max_status = kOK; |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
250 // Even if we encounter an error, we still process pending OOB | 238 // Even if we encounter an error, we still process pending OOB |
251 // messages so that we don't lose the message notification. | 239 // messages so that we don't lose the message notification. |
252 min_priority = (((max_status == kOK) && allow_normal_messages && !paused()) | 240 min_priority = (((max_status == kOK) && allow_normal_messages && !paused()) |
253 ? Message::kNormalPriority | 241 ? Message::kNormalPriority |
254 : Message::kOOBPriority); | 242 : Message::kOOBPriority); |
255 message = DequeueMessage(min_priority); | 243 message = DequeueMessage(min_priority); |
256 } | 244 } |
257 return max_status; | 245 return max_status; |
258 } | 246 } |
259 | 247 |
260 | |
261 MessageHandler::MessageStatus MessageHandler::HandleNextMessage() { | 248 MessageHandler::MessageStatus MessageHandler::HandleNextMessage() { |
262 // We can only call HandleNextMessage when this handler is not | 249 // We can only call HandleNextMessage when this handler is not |
263 // assigned to a thread pool. | 250 // assigned to a thread pool. |
264 MonitorLocker ml(&monitor_); | 251 MonitorLocker ml(&monitor_); |
265 ASSERT(pool_ == NULL); | 252 ASSERT(pool_ == NULL); |
266 ASSERT(!delete_me_); | 253 ASSERT(!delete_me_); |
267 #if defined(DEBUG) | 254 #if defined(DEBUG) |
268 CheckAccess(); | 255 CheckAccess(); |
269 #endif | 256 #endif |
270 return HandleMessages(&ml, true, false); | 257 return HandleMessages(&ml, true, false); |
271 } | 258 } |
272 | 259 |
273 | |
274 MessageHandler::MessageStatus MessageHandler::HandleAllMessages() { | 260 MessageHandler::MessageStatus MessageHandler::HandleAllMessages() { |
275 // We can only call HandleAllMessages when this handler is not | 261 // We can only call HandleAllMessages when this handler is not |
276 // assigned to a thread pool. | 262 // assigned to a thread pool. |
277 MonitorLocker ml(&monitor_); | 263 MonitorLocker ml(&monitor_); |
278 ASSERT(pool_ == NULL); | 264 ASSERT(pool_ == NULL); |
279 ASSERT(!delete_me_); | 265 ASSERT(!delete_me_); |
280 #if defined(DEBUG) | 266 #if defined(DEBUG) |
281 CheckAccess(); | 267 CheckAccess(); |
282 #endif | 268 #endif |
283 return HandleMessages(&ml, true, true); | 269 return HandleMessages(&ml, true, true); |
284 } | 270 } |
285 | 271 |
286 | |
287 MessageHandler::MessageStatus MessageHandler::HandleOOBMessages() { | 272 MessageHandler::MessageStatus MessageHandler::HandleOOBMessages() { |
288 if (!oob_message_handling_allowed_) { | 273 if (!oob_message_handling_allowed_) { |
289 return kOK; | 274 return kOK; |
290 } | 275 } |
291 MonitorLocker ml(&monitor_); | 276 MonitorLocker ml(&monitor_); |
292 ASSERT(!delete_me_); | 277 ASSERT(!delete_me_); |
293 #if defined(DEBUG) | 278 #if defined(DEBUG) |
294 CheckAccess(); | 279 CheckAccess(); |
295 #endif | 280 #endif |
296 return HandleMessages(&ml, false, false); | 281 return HandleMessages(&ml, false, false); |
297 } | 282 } |
298 | 283 |
299 | |
300 bool MessageHandler::ShouldPauseOnStart(MessageStatus status) const { | 284 bool MessageHandler::ShouldPauseOnStart(MessageStatus status) const { |
301 Isolate* owning_isolate = isolate(); | 285 Isolate* owning_isolate = isolate(); |
302 if (owning_isolate == NULL) { | 286 if (owning_isolate == NULL) { |
303 return false; | 287 return false; |
304 } | 288 } |
305 // If we are restarting or shutting down, we do not want to honor | 289 // If we are restarting or shutting down, we do not want to honor |
306 // should_pause_on_start or should_pause_on_exit. | 290 // should_pause_on_start or should_pause_on_exit. |
307 return (status != MessageHandler::kRestart && | 291 return (status != MessageHandler::kRestart && |
308 status != MessageHandler::kShutdown) && | 292 status != MessageHandler::kShutdown) && |
309 should_pause_on_start() && owning_isolate->is_runnable(); | 293 should_pause_on_start() && owning_isolate->is_runnable(); |
310 } | 294 } |
311 | 295 |
312 | |
313 bool MessageHandler::ShouldPauseOnExit(MessageStatus status) const { | 296 bool MessageHandler::ShouldPauseOnExit(MessageStatus status) const { |
314 Isolate* owning_isolate = isolate(); | 297 Isolate* owning_isolate = isolate(); |
315 if (owning_isolate == NULL) { | 298 if (owning_isolate == NULL) { |
316 return false; | 299 return false; |
317 } | 300 } |
318 return (status != MessageHandler::kRestart && | 301 return (status != MessageHandler::kRestart && |
319 status != MessageHandler::kShutdown) && | 302 status != MessageHandler::kShutdown) && |
320 should_pause_on_exit() && owning_isolate->is_runnable(); | 303 should_pause_on_exit() && owning_isolate->is_runnable(); |
321 } | 304 } |
322 | 305 |
323 | |
324 bool MessageHandler::HasOOBMessages() { | 306 bool MessageHandler::HasOOBMessages() { |
325 MonitorLocker ml(&monitor_); | 307 MonitorLocker ml(&monitor_); |
326 return !oob_queue_->IsEmpty(); | 308 return !oob_queue_->IsEmpty(); |
327 } | 309 } |
328 | 310 |
329 | |
330 void MessageHandler::TaskCallback() { | 311 void MessageHandler::TaskCallback() { |
331 ASSERT(Isolate::Current() == NULL); | 312 ASSERT(Isolate::Current() == NULL); |
332 MessageStatus status = kOK; | 313 MessageStatus status = kOK; |
333 bool run_end_callback = false; | 314 bool run_end_callback = false; |
334 bool delete_me = false; | 315 bool delete_me = false; |
335 EndCallback end_callback = NULL; | 316 EndCallback end_callback = NULL; |
336 CallbackData callback_data = 0; | 317 CallbackData callback_data = 0; |
337 { | 318 { |
338 // We will occasionally release and reacquire this monitor in this | 319 // We will occasionally release and reacquire this monitor in this |
339 // function. Whenever we reacquire the monitor we *must* process | 320 // function. Whenever we reacquire the monitor we *must* process |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
438 if (run_end_callback) { | 419 if (run_end_callback) { |
439 ASSERT(end_callback != NULL); | 420 ASSERT(end_callback != NULL); |
440 end_callback(callback_data); | 421 end_callback(callback_data); |
441 // The handler may have been deleted after this point. | 422 // The handler may have been deleted after this point. |
442 } | 423 } |
443 if (delete_me) { | 424 if (delete_me) { |
444 delete this; | 425 delete this; |
445 } | 426 } |
446 } | 427 } |
447 | 428 |
448 | |
449 void MessageHandler::ClosePort(Dart_Port port) { | 429 void MessageHandler::ClosePort(Dart_Port port) { |
450 MonitorLocker ml(&monitor_); | 430 MonitorLocker ml(&monitor_); |
451 if (FLAG_trace_isolates) { | 431 if (FLAG_trace_isolates) { |
452 OS::Print( | 432 OS::Print( |
453 "[-] Closing port:\n" | 433 "[-] Closing port:\n" |
454 "\thandler: %s\n" | 434 "\thandler: %s\n" |
455 "\tport: %" Pd64 | 435 "\tport: %" Pd64 |
456 "\n" | 436 "\n" |
457 "\tports: live(%" Pd ")\n", | 437 "\tports: live(%" Pd ")\n", |
458 name(), port, live_ports_); | 438 name(), port, live_ports_); |
459 } | 439 } |
460 } | 440 } |
461 | 441 |
462 | |
463 void MessageHandler::CloseAllPorts() { | 442 void MessageHandler::CloseAllPorts() { |
464 MonitorLocker ml(&monitor_); | 443 MonitorLocker ml(&monitor_); |
465 if (FLAG_trace_isolates) { | 444 if (FLAG_trace_isolates) { |
466 OS::Print( | 445 OS::Print( |
467 "[-] Closing all ports:\n" | 446 "[-] Closing all ports:\n" |
468 "\thandler: %s\n", | 447 "\thandler: %s\n", |
469 name()); | 448 name()); |
470 } | 449 } |
471 queue_->Clear(); | 450 queue_->Clear(); |
472 oob_queue_->Clear(); | 451 oob_queue_->Clear(); |
473 } | 452 } |
474 | 453 |
475 | |
476 void MessageHandler::RequestDeletion() { | 454 void MessageHandler::RequestDeletion() { |
477 ASSERT(OwnedByPortMap()); | 455 ASSERT(OwnedByPortMap()); |
478 { | 456 { |
479 MonitorLocker ml(&monitor_); | 457 MonitorLocker ml(&monitor_); |
480 if (task_ != NULL) { | 458 if (task_ != NULL) { |
481 // This message handler currently has a task running on the thread pool. | 459 // This message handler currently has a task running on the thread pool. |
482 delete_me_ = true; | 460 delete_me_ = true; |
483 return; | 461 return; |
484 } | 462 } |
485 } | 463 } |
486 | 464 |
487 // This message handler has no current task. Delete it. | 465 // This message handler has no current task. Delete it. |
488 delete this; | 466 delete this; |
489 } | 467 } |
490 | 468 |
491 | |
492 void MessageHandler::increment_live_ports() { | 469 void MessageHandler::increment_live_ports() { |
493 MonitorLocker ml(&monitor_); | 470 MonitorLocker ml(&monitor_); |
494 #if defined(DEBUG) | 471 #if defined(DEBUG) |
495 CheckAccess(); | 472 CheckAccess(); |
496 #endif | 473 #endif |
497 live_ports_++; | 474 live_ports_++; |
498 } | 475 } |
499 | 476 |
500 | |
501 void MessageHandler::decrement_live_ports() { | 477 void MessageHandler::decrement_live_ports() { |
502 MonitorLocker ml(&monitor_); | 478 MonitorLocker ml(&monitor_); |
503 #if defined(DEBUG) | 479 #if defined(DEBUG) |
504 CheckAccess(); | 480 CheckAccess(); |
505 #endif | 481 #endif |
506 live_ports_--; | 482 live_ports_--; |
507 } | 483 } |
508 | 484 |
509 | |
510 void MessageHandler::PausedOnStart(bool paused) { | 485 void MessageHandler::PausedOnStart(bool paused) { |
511 MonitorLocker ml(&monitor_); | 486 MonitorLocker ml(&monitor_); |
512 PausedOnStartLocked(&ml, paused); | 487 PausedOnStartLocked(&ml, paused); |
513 } | 488 } |
514 | 489 |
515 | |
516 void MessageHandler::DebugDump() { | 490 void MessageHandler::DebugDump() { |
517 PortMap::DebugDumpForMessageHandler(this); | 491 PortMap::DebugDumpForMessageHandler(this); |
518 } | 492 } |
519 | 493 |
520 | |
521 void MessageHandler::PausedOnStartLocked(MonitorLocker* ml, bool paused) { | 494 void MessageHandler::PausedOnStartLocked(MonitorLocker* ml, bool paused) { |
522 if (paused) { | 495 if (paused) { |
523 ASSERT(!is_paused_on_start_); | 496 ASSERT(!is_paused_on_start_); |
524 is_paused_on_start_ = true; | 497 is_paused_on_start_ = true; |
525 paused_timestamp_ = OS::GetCurrentTimeMillis(); | 498 paused_timestamp_ = OS::GetCurrentTimeMillis(); |
526 } else { | 499 } else { |
527 ASSERT(is_paused_on_start_); | 500 ASSERT(is_paused_on_start_); |
528 is_paused_on_start_ = false; | 501 is_paused_on_start_ = false; |
529 paused_timestamp_ = -1; | 502 paused_timestamp_ = -1; |
530 } | 503 } |
531 if (is_paused_on_start_) { | 504 if (is_paused_on_start_) { |
532 // Temporarily release the monitor when calling out to | 505 // Temporarily release the monitor when calling out to |
533 // NotifyPauseOnStart. This avoids a dead lock that can occur | 506 // NotifyPauseOnStart. This avoids a dead lock that can occur |
534 // when this message handler tries to post a message while a | 507 // when this message handler tries to post a message while a |
535 // message is being posted to it. | 508 // message is being posted to it. |
536 ml->Exit(); | 509 ml->Exit(); |
537 NotifyPauseOnStart(); | 510 NotifyPauseOnStart(); |
538 ml->Enter(); | 511 ml->Enter(); |
539 } else { | 512 } else { |
540 // Resumed. Clear the resume request of the owning isolate. | 513 // Resumed. Clear the resume request of the owning isolate. |
541 Isolate* owning_isolate = isolate(); | 514 Isolate* owning_isolate = isolate(); |
542 if (owning_isolate != NULL) { | 515 if (owning_isolate != NULL) { |
543 owning_isolate->GetAndClearResumeRequest(); | 516 owning_isolate->GetAndClearResumeRequest(); |
544 } | 517 } |
545 } | 518 } |
546 } | 519 } |
547 | 520 |
548 | |
549 void MessageHandler::PausedOnExit(bool paused) { | 521 void MessageHandler::PausedOnExit(bool paused) { |
550 MonitorLocker ml(&monitor_); | 522 MonitorLocker ml(&monitor_); |
551 PausedOnExitLocked(&ml, paused); | 523 PausedOnExitLocked(&ml, paused); |
552 } | 524 } |
553 | 525 |
554 | |
555 void MessageHandler::PausedOnExitLocked(MonitorLocker* ml, bool paused) { | 526 void MessageHandler::PausedOnExitLocked(MonitorLocker* ml, bool paused) { |
556 if (paused) { | 527 if (paused) { |
557 ASSERT(!is_paused_on_exit_); | 528 ASSERT(!is_paused_on_exit_); |
558 is_paused_on_exit_ = true; | 529 is_paused_on_exit_ = true; |
559 paused_timestamp_ = OS::GetCurrentTimeMillis(); | 530 paused_timestamp_ = OS::GetCurrentTimeMillis(); |
560 } else { | 531 } else { |
561 ASSERT(is_paused_on_exit_); | 532 ASSERT(is_paused_on_exit_); |
562 is_paused_on_exit_ = false; | 533 is_paused_on_exit_ = false; |
563 paused_timestamp_ = -1; | 534 paused_timestamp_ = -1; |
564 } | 535 } |
565 if (is_paused_on_exit_) { | 536 if (is_paused_on_exit_) { |
566 // Temporarily release the monitor when calling out to | 537 // Temporarily release the monitor when calling out to |
567 // NotifyPauseOnExit. This avoids a dead lock that can | 538 // NotifyPauseOnExit. This avoids a dead lock that can |
568 // occur when this message handler tries to post a message | 539 // occur when this message handler tries to post a message |
569 // while a message is being posted to it. | 540 // while a message is being posted to it. |
570 ml->Exit(); | 541 ml->Exit(); |
571 NotifyPauseOnExit(); | 542 NotifyPauseOnExit(); |
572 ml->Enter(); | 543 ml->Enter(); |
573 } else { | 544 } else { |
574 // Resumed. Clear the resume request of the owning isolate. | 545 // Resumed. Clear the resume request of the owning isolate. |
575 Isolate* owning_isolate = isolate(); | 546 Isolate* owning_isolate = isolate(); |
576 if (owning_isolate != NULL) { | 547 if (owning_isolate != NULL) { |
577 owning_isolate->GetAndClearResumeRequest(); | 548 owning_isolate->GetAndClearResumeRequest(); |
578 } | 549 } |
579 } | 550 } |
580 } | 551 } |
581 | 552 |
582 | |
583 MessageHandler::AcquiredQueues::AcquiredQueues(MessageHandler* handler) | 553 MessageHandler::AcquiredQueues::AcquiredQueues(MessageHandler* handler) |
584 : handler_(handler), ml_(&handler->monitor_) { | 554 : handler_(handler), ml_(&handler->monitor_) { |
585 ASSERT(handler != NULL); | 555 ASSERT(handler != NULL); |
586 handler_->oob_message_handling_allowed_ = false; | 556 handler_->oob_message_handling_allowed_ = false; |
587 } | 557 } |
588 | 558 |
589 | |
590 MessageHandler::AcquiredQueues::~AcquiredQueues() { | 559 MessageHandler::AcquiredQueues::~AcquiredQueues() { |
591 ASSERT(handler_ != NULL); | 560 ASSERT(handler_ != NULL); |
592 handler_->oob_message_handling_allowed_ = true; | 561 handler_->oob_message_handling_allowed_ = true; |
593 } | 562 } |
594 | 563 |
595 } // namespace dart | 564 } // namespace dart |
OLD | NEW |