| 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 #include "vm/port.h" | 6 #include "vm/port.h" |
| 7 #include "vm/dart.h" | 7 #include "vm/dart.h" |
| 8 | 8 |
| 9 namespace dart { | 9 namespace dart { |
| 10 | 10 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 | 27 |
| 28 DISALLOW_COPY_AND_ASSIGN(MessageHandlerTask); | 28 DISALLOW_COPY_AND_ASSIGN(MessageHandlerTask); |
| 29 }; | 29 }; |
| 30 | 30 |
| 31 | 31 |
| 32 MessageHandler::MessageHandler() | 32 MessageHandler::MessageHandler() |
| 33 : queue_(new MessageQueue()), | 33 : queue_(new MessageQueue()), |
| 34 oob_queue_(new MessageQueue()), | 34 oob_queue_(new MessageQueue()), |
| 35 control_ports_(0), | 35 control_ports_(0), |
| 36 live_ports_(0), | 36 live_ports_(0), |
| 37 pause_on_start_(false), |
| 38 pause_on_exit_(false), |
| 39 paused_on_exit_(false), |
| 37 pool_(NULL), | 40 pool_(NULL), |
| 38 task_(NULL), | 41 task_(NULL), |
| 39 start_callback_(NULL), | 42 start_callback_(NULL), |
| 40 end_callback_(NULL), | 43 end_callback_(NULL), |
| 41 callback_data_(0) { | 44 callback_data_(0) { |
| 42 ASSERT(queue_ != NULL); | 45 ASSERT(queue_ != NULL); |
| 43 ASSERT(oob_queue_ != NULL); | 46 ASSERT(oob_queue_ != NULL); |
| 44 } | 47 } |
| 45 | 48 |
| 46 | 49 |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 | 193 |
| 191 void MessageHandler::TaskCallback() { | 194 void MessageHandler::TaskCallback() { |
| 192 ASSERT(Isolate::Current() == NULL); | 195 ASSERT(Isolate::Current() == NULL); |
| 193 bool ok = true; | 196 bool ok = true; |
| 194 bool run_end_callback = false; | 197 bool run_end_callback = false; |
| 195 { | 198 { |
| 196 MonitorLocker ml(&monitor_); | 199 MonitorLocker ml(&monitor_); |
| 197 // Initialize the message handler by running its start function, | 200 // Initialize the message handler by running its start function, |
| 198 // if we have one. For an isolate, this will run the isolate's | 201 // if we have one. For an isolate, this will run the isolate's |
| 199 // main() function. | 202 // main() function. |
| 203 if (pause_on_start()) { |
| 204 HandleMessages(false, false); |
| 205 if (pause_on_start()) { |
| 206 // Still paused. |
| 207 task_ = NULL; // No task in queue. |
| 208 return; |
| 209 } |
| 210 } |
| 211 |
| 200 if (start_callback_) { | 212 if (start_callback_) { |
| 201 monitor_.Exit(); | 213 monitor_.Exit(); |
| 202 ok = start_callback_(callback_data_); | 214 ok = start_callback_(callback_data_); |
| 203 ASSERT(Isolate::Current() == NULL); | 215 ASSERT(Isolate::Current() == NULL); |
| 204 start_callback_ = NULL; | 216 start_callback_ = NULL; |
| 205 monitor_.Enter(); | 217 monitor_.Enter(); |
| 206 } | 218 } |
| 207 | 219 |
| 208 // Handle any pending messages for this message handler. | 220 // Handle any pending messages for this message handler. |
| 209 if (ok) { | 221 if (ok) { |
| 210 ok = HandleMessages(true, true); | 222 ok = HandleMessages(true, true); |
| 211 } | 223 } |
| 212 task_ = NULL; // No task in queue. | 224 task_ = NULL; // No task in queue. |
| 213 | 225 |
| 214 if (!ok || !HasLivePorts()) { | 226 if (!ok || !HasLivePorts()) { |
| 215 if (FLAG_trace_isolates) { | 227 if (pause_on_exit()) { |
| 228 paused_on_exit_ = true; |
| 229 } else { |
| 230 if (FLAG_trace_isolates) { |
| 216 OS::Print("[-] Stopping message handler (%s):\n" | 231 OS::Print("[-] Stopping message handler (%s):\n" |
| 217 "\thandler: %s\n", | 232 "\thandler: %s\n", |
| 218 (ok ? "no live ports" : "error"), | 233 (ok ? "no live ports" : "error"), |
| 219 name()); | 234 name()); |
| 235 } |
| 236 pool_ = NULL; |
| 237 run_end_callback = true; |
| 238 paused_on_exit_ = false; |
| 220 } | 239 } |
| 221 pool_ = NULL; | |
| 222 run_end_callback = true; | |
| 223 } | 240 } |
| 224 } | 241 } |
| 225 if (run_end_callback && end_callback_ != NULL) { | 242 if (run_end_callback && end_callback_ != NULL) { |
| 226 end_callback_(callback_data_); | 243 end_callback_(callback_data_); |
| 227 // The handler may have been deleted after this point. | 244 // The handler may have been deleted after this point. |
| 228 } | 245 } |
| 229 } | 246 } |
| 230 | 247 |
| 231 | 248 |
| 232 void MessageHandler::ClosePort(Dart_Port port) { | 249 void MessageHandler::ClosePort(Dart_Port port) { |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 281 | 298 |
| 282 void MessageHandler::decrement_control_ports() { | 299 void MessageHandler::decrement_control_ports() { |
| 283 MonitorLocker ml(&monitor_); | 300 MonitorLocker ml(&monitor_); |
| 284 #if defined(DEBUG) | 301 #if defined(DEBUG) |
| 285 CheckAccess(); | 302 CheckAccess(); |
| 286 #endif | 303 #endif |
| 287 control_ports_--; | 304 control_ports_--; |
| 288 } | 305 } |
| 289 | 306 |
| 290 } // namespace dart | 307 } // namespace dart |
| OLD | NEW |