Index: runtime/vm/message.cc |
=================================================================== |
--- runtime/vm/message.cc (revision 3603) |
+++ runtime/vm/message.cc (working copy) |
@@ -2,10 +2,76 @@ |
// for details. All rights reserved. Use of this source code is governed by a |
// BSD-style license that can be found in the LICENSE file. |
-#include "vm/message_queue.h" |
+#include "vm/message.h" |
namespace dart { |
+DECLARE_FLAG(bool, trace_isolates); |
+ |
+ |
+MessageHandler::MessageHandler() |
+ : live_ports_(0), |
+ queue_(new MessageQueue()) { |
+ ASSERT(queue_ != NULL); |
+} |
+ |
+ |
+MessageHandler::~MessageHandler() { |
+ delete queue_; |
+} |
+ |
+ |
+const char* MessageHandler::name() const { |
+ return "<unnamed>"; |
+} |
+ |
+ |
+#if defined(DEBUG) |
+void MessageHandler::CheckAccess() { |
+ // By default there is no checking. |
+} |
+#endif |
+ |
+ |
+void MessageHandler::MessageNotify(Message::Priority priority) { |
+ // By default, there is no custom message notification. |
+} |
+ |
+ |
+void MessageHandler::PostMessage(Message* message) { |
+ if (FLAG_trace_isolates) { |
+ const char* source_name = "<native code>"; |
+ Isolate* source_isolate = Isolate::Current(); |
+ if (source_isolate) { |
+ source_name = source_isolate->name(); |
+ } |
+ OS::Print("[>] Posting message:\n" |
+ "\tsource: %s\n" |
+ "\treply_port: %lld\n" |
+ "\tdest: %s\n" |
+ "\tdest_port: %lld\n", |
+ source_name, message->reply_port(), name(), message->dest_port()); |
+ } |
+ |
+ Message::Priority priority = message->priority(); |
+ queue()->Enqueue(message); |
+ message = NULL; // Do not access message. May have been deleted. |
+ |
+ // Invoke any custom message notification. |
+ MessageNotify(priority); |
+} |
+ |
+ |
+void MessageHandler::ClosePort(Dart_Port port) { |
+ queue()->Flush(port); |
+} |
+ |
+ |
+void MessageHandler::CloseAllPorts() { |
+ queue()->FlushAll(); |
+} |
+ |
+ |
MessageQueue::MessageQueue() { |
for (int p = Message::kFirstPriority; p < Message::kNumPriorities; p++) { |
head_[p] = NULL; |
@@ -77,20 +143,22 @@ |
Message* MessageQueue::Dequeue(int64_t millis) { |
ASSERT(millis >= 0); |
- MonitorLocker ml(&monitor_); |
+ monitor_.Enter(); |
Message* result = DequeueNoWaitHoldsLock(); |
if (result == NULL) { |
// No message available at any priority. |
- ml.Wait(millis); |
+ monitor_.Wait(millis); |
result = DequeueNoWaitHoldsLock(); |
} |
+ |
+ monitor_.Exit(); |
return result; |
} |
void MessageQueue::Flush(Dart_Port port) { |
- MonitorLocker ml(&monitor_); |
+ monitor_.Enter(); |
Søren Gjesse
2012/01/27 13:33:14
In runtime/bin/thread.h we have a MonitorLocker wh
siva
2012/01/28 00:21:05
We should re-evaluate if MonitorLocker needs to be
turnidge
2012/01/31 20:04:31
I have partially addressed this by making StackRes
turnidge
2012/01/31 20:04:31
I have changed StackResource to function reasonabl
|
for (int p = Message::kFirstPriority; p < Message::kNumPriorities; p++) { |
Message* cur = head_[p]; |
Message* prev = NULL; |
@@ -113,6 +181,7 @@ |
} |
tail_[p] = prev; |
} |
+ monitor_.Exit(); |
} |