Chromium Code Reviews| Index: runtime/vm/isolate.cc |
| =================================================================== |
| --- runtime/vm/isolate.cc (revision 448) |
| +++ runtime/vm/isolate.cc (working copy) |
| @@ -5,7 +5,6 @@ |
| #include "vm/isolate.h" |
| #include "include/dart_api.h" |
|
siva
2011/10/14 21:01:52
The style has been to leave a blank line here (i.e
turnidge
2011/10/14 23:08:02
Done.
|
| - |
| #include "vm/assert.h" |
| #include "vm/bigint_store.h" |
| #include "vm/code_index_table.h" |
| @@ -13,6 +12,7 @@ |
| #include "vm/dart_api_state.h" |
| #include "vm/debuginfo.h" |
| #include "vm/heap.h" |
| +#include "vm/message_queue.h" |
| #include "vm/object_store.h" |
| #include "vm/parser.h" |
| #include "vm/port.h" |
| @@ -23,6 +23,7 @@ |
| #include "vm/timer.h" |
| #include "vm/visitor.h" |
|
siva
2011/10/14 21:01:52
extra blank line here.
turnidge
2011/10/14 23:08:02
Done.
|
| + |
| namespace dart { |
| DEFINE_FLAG(bool, report_invocation_count, false, |
| @@ -32,8 +33,9 @@ |
| Isolate::Isolate() |
| : store_buffer_(), |
| - monitor_(NULL), |
| message_queue_(NULL), |
| + post_message_callback_(NULL), |
| + close_port_callback_(NULL), |
| active_ports_(0), |
| heap_(NULL), |
| object_store_(NULL), |
| @@ -62,7 +64,6 @@ |
| Isolate::~Isolate() { |
| - delete monitor_; |
| delete message_queue_; |
| delete heap_; |
| delete object_store_; |
| @@ -74,6 +75,31 @@ |
| } |
| +static bool StandardPostMessageCallback(Dart_Isolate dart_isolate, |
| + Dart_Port dest_port, |
| + Dart_Port reply_port, |
| + Dart_Message dart_message) { |
| + Isolate* isolate = reinterpret_cast<Isolate*>(dart_isolate); |
| + ASSERT(isolate != NULL); |
| + PortMessage* message = new PortMessage(dest_port, reply_port, dart_message); |
| + isolate->message_queue()->Enqueue(message); |
| + return true; |
| +} |
| + |
| + |
| +static void StandardClosePortCallback(Dart_Isolate dart_isolate, |
| + Dart_Port port) { |
| + // Remove the pending messages for this port. |
| + Isolate* isolate = reinterpret_cast<Isolate*>(dart_isolate); |
| + ASSERT(isolate != NULL); |
| + if (port == kCloseAllPorts) { |
| + isolate->message_queue()->FlushAll(); |
| + } else { |
| + isolate->message_queue()->Flush(port); |
| + } |
| +} |
| + |
| + |
| Isolate* Isolate::Init() { |
| Isolate* result = new Isolate(); |
| ASSERT(result != NULL); |
| @@ -82,14 +108,12 @@ |
| // the current isolate. |
| SetCurrent(result); |
| - // Setup the isolate monitor. |
| - Monitor* monitor = new Monitor(); |
| - ASSERT(monitor != NULL); |
| - result->set_monitor(monitor); |
| - |
| + // Set up the isolate message queue. |
| MessageQueue* queue = new MessageQueue(); |
| ASSERT(queue != NULL); |
| result->set_message_queue(queue); |
| + result->set_post_message_callback(&StandardPostMessageCallback); |
| + result->set_close_port_callback(&StandardClosePortCallback); |
| // Setup the Dart API state. |
| ApiState* state = new ApiState(); |
| @@ -179,10 +203,6 @@ |
| delete message_queue(); |
| set_message_queue(NULL); |
| - // Remove the monitor associated with this isolate. |
| - delete monitor(); |
| - set_monitor(NULL); |
| - |
| // Dump all accumalated timer data for the isolate. |
| timer_list_.ReportTimers(); |
| if (FLAG_report_invocation_count) { |
| @@ -212,6 +232,30 @@ |
| } |
| +void Isolate::StandardRunLoop() { |
| + ASSERT(long_jump_base() != NULL); |
| + ASSERT(post_message_callback() == &StandardPostMessageCallback); |
| + ASSERT(close_port_callback() == &StandardClosePortCallback); |
| + |
| + while (active_ports() > 0) { |
| + Zone zone; |
| + HandleScope handle_scope; |
| + |
| + PortMessage* message = message_queue()->Dequeue(); |
| + if (message == NULL) { |
| + message_queue()->Wait(0); |
| + message = message_queue()->Dequeue(); |
| + } |
|
siva
2011/10/14 21:01:52
Why not make the Dequeue method wait if there is n
turnidge
2011/10/14 23:08:02
Done. Thanks, that's better.
|
| + if (message) { |
| + Dart_HandleMessage( |
| + message->dest_port(), message->reply_port(), message->data()); |
| + // message->Handle(); |
|
siva
2011/10/14 21:01:52
Is this commented out code still necessary?
turnidge
2011/10/14 23:08:02
Removed.
|
| + delete message; |
| + } |
| + } |
| +} |
| + |
| + |
| void Isolate::VisitObjectPointers(ObjectPointerVisitor* visitor, |
| bool validate_frames) { |
| ASSERT(visitor != NULL); |