Chromium Code Reviews| 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/port.h" | 9 #include "vm/port.h" |
| 10 #include "vm/thread_interrupter.h" | 10 #include "vm/thread_interrupter.h" |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 35 MessageHandler::MessageHandler() | 35 MessageHandler::MessageHandler() |
| 36 : queue_(new MessageQueue()), | 36 : queue_(new MessageQueue()), |
| 37 oob_queue_(new MessageQueue()), | 37 oob_queue_(new MessageQueue()), |
| 38 oob_message_handling_allowed_(true), | 38 oob_message_handling_allowed_(true), |
| 39 live_ports_(0), | 39 live_ports_(0), |
| 40 paused_(0), | 40 paused_(0), |
| 41 pause_on_start_(false), | 41 pause_on_start_(false), |
| 42 pause_on_exit_(false), | 42 pause_on_exit_(false), |
| 43 paused_on_start_(false), | 43 paused_on_start_(false), |
| 44 paused_on_exit_(false), | 44 paused_on_exit_(false), |
| 45 pool_(NULL), | 45 running_(false), |
| 46 task_(NULL), | 46 task_(NULL), |
| 47 start_callback_(NULL), | 47 start_callback_(NULL), |
| 48 end_callback_(NULL), | 48 end_callback_(NULL), |
| 49 callback_data_(0) { | 49 callback_data_(0) { |
| 50 ASSERT(queue_ != NULL); | 50 ASSERT(queue_ != NULL); |
| 51 ASSERT(oob_queue_ != NULL); | 51 ASSERT(oob_queue_ != NULL); |
| 52 } | 52 } |
| 53 | 53 |
| 54 | 54 |
| 55 MessageHandler::~MessageHandler() { | 55 MessageHandler::~MessageHandler() { |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 68 // By default there is no checking. | 68 // By default there is no checking. |
| 69 } | 69 } |
| 70 #endif | 70 #endif |
| 71 | 71 |
| 72 | 72 |
| 73 void MessageHandler::MessageNotify(Message::Priority priority) { | 73 void MessageHandler::MessageNotify(Message::Priority priority) { |
| 74 // By default, there is no custom message notification. | 74 // By default, there is no custom message notification. |
| 75 } | 75 } |
| 76 | 76 |
| 77 | 77 |
| 78 void MessageHandler::Run(ThreadPool* pool, | 78 void MessageHandler::Run(StartCallback start_callback, |
| 79 StartCallback start_callback, | |
| 80 EndCallback end_callback, | 79 EndCallback end_callback, |
| 81 CallbackData data) { | 80 CallbackData data) { |
| 82 MonitorLocker ml(&monitor_); | 81 MonitorLocker ml(&monitor_); |
| 83 if (FLAG_trace_isolates) { | 82 if (FLAG_trace_isolates) { |
| 84 OS::Print("[+] Starting message handler:\n" | 83 OS::Print("[+] Starting message handler:\n" |
| 85 "\thandler: %s\n", | 84 "\thandler: %s\n", |
| 86 name()); | 85 name()); |
| 87 } | 86 } |
| 88 ASSERT(pool_ == NULL); | 87 ASSERT(!running_); |
| 89 pool_ = pool; | 88 running_ = true; |
|
turnidge
2015/06/30 22:15:46
I think that "running_" is a bit confusing as a na
zra
2015/07/20 22:23:39
Done.
| |
| 90 start_callback_ = start_callback; | 89 start_callback_ = start_callback; |
| 91 end_callback_ = end_callback; | 90 end_callback_ = end_callback; |
| 92 callback_data_ = data; | 91 callback_data_ = data; |
| 93 task_ = new MessageHandlerTask(this); | 92 task_ = new MessageHandlerTask(this); |
| 94 pool_->Run(task_); | 93 ThreadPool::Run(task_); |
| 95 } | 94 } |
| 96 | 95 |
| 97 | 96 |
| 98 void MessageHandler::PostMessage(Message* message, bool before_events) { | 97 void MessageHandler::PostMessage(Message* message, bool before_events) { |
| 99 Message::Priority saved_priority; | 98 Message::Priority saved_priority; |
| 100 { | 99 { |
| 101 MonitorLocker ml(&monitor_); | 100 MonitorLocker ml(&monitor_); |
| 102 if (FLAG_trace_isolates) { | 101 if (FLAG_trace_isolates) { |
| 103 const char* source_name = "<native code>"; | 102 const char* source_name = "<native code>"; |
| 104 Isolate* source_isolate = Isolate::Current(); | 103 Isolate* source_isolate = Isolate::Current(); |
| 105 if (source_isolate) { | 104 if (source_isolate) { |
| 106 source_name = source_isolate->name(); | 105 source_name = source_isolate->name(); |
| 107 } | 106 } |
| 108 OS::Print("[>] Posting message:\n" | 107 OS::Print("[>] Posting message:\n" |
| 109 "\tlen: %" Pd "\n" | 108 "\tlen: %" Pd "\n" |
| 110 "\tsource: %s\n" | 109 "\tsource: %s\n" |
| 111 "\tdest: %s\n" | 110 "\tdest: %s\n" |
| 112 "\tdest_port: %" Pd64 "\n", | 111 "\tdest_port: %" Pd64 "\n", |
| 113 message->len(), source_name, name(), message->dest_port()); | 112 message->len(), source_name, name(), message->dest_port()); |
| 114 } | 113 } |
| 115 | 114 |
| 116 saved_priority = message->priority(); | 115 saved_priority = message->priority(); |
| 117 if (message->IsOOB()) { | 116 if (message->IsOOB()) { |
| 118 oob_queue_->Enqueue(message, before_events); | 117 oob_queue_->Enqueue(message, before_events); |
| 119 } else { | 118 } else { |
| 120 queue_->Enqueue(message, before_events); | 119 queue_->Enqueue(message, before_events); |
| 121 } | 120 } |
| 122 message = NULL; // Do not access message. May have been deleted. | 121 message = NULL; // Do not access message. May have been deleted. |
| 123 | 122 |
| 124 if (pool_ != NULL && task_ == NULL) { | 123 if (running_ && task_ == NULL) { |
| 125 task_ = new MessageHandlerTask(this); | 124 task_ = new MessageHandlerTask(this); |
| 126 pool_->Run(task_); | 125 ThreadPool::Run(task_); |
| 127 } | 126 } |
| 128 } | 127 } |
| 129 // Invoke any custom message notification. | 128 // Invoke any custom message notification. |
| 130 MessageNotify(saved_priority); | 129 MessageNotify(saved_priority); |
| 131 } | 130 } |
| 132 | 131 |
| 133 | 132 |
| 134 Message* MessageHandler::DequeueMessage(Message::Priority min_priority) { | 133 Message* MessageHandler::DequeueMessage(Message::Priority min_priority) { |
| 135 // TODO(turnidge): Add assert that monitor_ is held here. | 134 // TODO(turnidge): Add assert that monitor_ is held here. |
| 136 Message* message = oob_queue_->Dequeue(); | 135 Message* message = oob_queue_->Dequeue(); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 196 min_priority = (allow_normal_messages && !paused()) ? | 195 min_priority = (allow_normal_messages && !paused()) ? |
| 197 Message::kNormalPriority : Message::kOOBPriority; | 196 Message::kNormalPriority : Message::kOOBPriority; |
| 198 message = DequeueMessage(min_priority); | 197 message = DequeueMessage(min_priority); |
| 199 } | 198 } |
| 200 return result; | 199 return result; |
| 201 } | 200 } |
| 202 | 201 |
| 203 | 202 |
| 204 bool MessageHandler::HandleNextMessage() { | 203 bool MessageHandler::HandleNextMessage() { |
| 205 // We can only call HandleNextMessage when this handler is not | 204 // We can only call HandleNextMessage when this handler is not |
| 206 // assigned to a thread pool. | 205 // assigned to a thread pool. |
|
turnidge
2015/06/30 22:15:46
Update comment.
zra
2015/07/20 22:23:39
Done.
| |
| 207 MonitorLocker ml(&monitor_); | 206 MonitorLocker ml(&monitor_); |
| 208 ASSERT(pool_ == NULL); | 207 ASSERT(!running_); |
| 209 #if defined(DEBUG) | 208 #if defined(DEBUG) |
| 210 CheckAccess(); | 209 CheckAccess(); |
| 211 #endif | 210 #endif |
| 212 return HandleMessages(true, false); | 211 return HandleMessages(true, false); |
| 213 } | 212 } |
| 214 | 213 |
| 215 | 214 |
| 216 bool MessageHandler::HandleOOBMessages() { | 215 bool MessageHandler::HandleOOBMessages() { |
| 217 if (!oob_message_handling_allowed_) { | 216 if (!oob_message_handling_allowed_) { |
| 218 return true; | 217 return true; |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 281 NotifyPauseOnExit(); | 280 NotifyPauseOnExit(); |
| 282 paused_on_exit_ = true; | 281 paused_on_exit_ = true; |
| 283 } | 282 } |
| 284 } else { | 283 } else { |
| 285 if (FLAG_trace_isolates) { | 284 if (FLAG_trace_isolates) { |
| 286 OS::Print("[-] Stopping message handler (%s):\n" | 285 OS::Print("[-] Stopping message handler (%s):\n" |
| 287 "\thandler: %s\n", | 286 "\thandler: %s\n", |
| 288 (ok ? "no live ports" : "error"), | 287 (ok ? "no live ports" : "error"), |
| 289 name()); | 288 name()); |
| 290 } | 289 } |
| 291 pool_ = NULL; | 290 running_ = false; |
| 292 run_end_callback = true; | 291 run_end_callback = true; |
| 293 paused_on_exit_ = false; | 292 paused_on_exit_ = false; |
| 294 } | 293 } |
| 295 } | 294 } |
| 296 } | 295 } |
| 297 if (run_end_callback && end_callback_ != NULL) { | 296 if (run_end_callback && end_callback_ != NULL) { |
| 298 end_callback_(callback_data_); | 297 end_callback_(callback_data_); |
| 299 // The handler may have been deleted after this point. | 298 // The handler may have been deleted after this point. |
| 300 } | 299 } |
| 301 } | 300 } |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 371 | 370 |
| 372 | 371 |
| 373 void MessageHandler::AcquireQueues(AcquiredQueues* acquired_queues) { | 372 void MessageHandler::AcquireQueues(AcquiredQueues* acquired_queues) { |
| 374 ASSERT(acquired_queues != NULL); | 373 ASSERT(acquired_queues != NULL); |
| 375 // No double dipping. | 374 // No double dipping. |
| 376 ASSERT(acquired_queues->handler_ == NULL); | 375 ASSERT(acquired_queues->handler_ == NULL); |
| 377 acquired_queues->Reset(this); | 376 acquired_queues->Reset(this); |
| 378 } | 377 } |
| 379 | 378 |
| 380 } // namespace dart | 379 } // namespace dart |
| OLD | NEW |