Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(203)

Unified Diff: runtime/vm/message.cc

Issue 749373002: - Implement Isolate.ping. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: runtime/vm/message.cc
===================================================================
--- runtime/vm/message.cc (revision 41942)
+++ runtime/vm/message.cc (working copy)
@@ -31,19 +31,49 @@
}
-void MessageQueue::Enqueue(Message* msg) {
+void MessageQueue::Enqueue(Message* msg, bool before_events) {
// Make sure messages are not reused.
ASSERT(msg->next_ == NULL);
- if (head_ == NULL) {
- // Only element in the queue.
- ASSERT(tail_ == NULL);
- head_ = msg;
- tail_ = msg;
+ if (!before_events) {
+ if (head_ == NULL) {
+ // Only element in the queue.
+ ASSERT(tail_ == NULL);
+ head_ = msg;
+ tail_ = msg;
+ } else {
+ ASSERT(tail_ != NULL);
+ // Append at the tail.
+ tail_->next_ = msg;
+ tail_ = msg;
+ }
} else {
- ASSERT(tail_ != NULL);
- // Append at the tail.
- tail_->next_ = msg;
- tail_ = msg;
+ ASSERT(msg->dest_port() == Message::kIllegalPort);
+ if (tail_ == NULL) {
+ ASSERT(head_ == NULL);
+ head_ = msg;
+ tail_ = msg;
siva 2014/12/01 19:48:05 The "only element in queue" case is common always
Ivan Posva 2014/12/12 20:21:46 Done.
+ } else if (head_->dest_port() != Message::kIllegalPort) {
+ msg->next_ = head_;
+ head_ = msg;
+ } else {
+ ASSERT(head_ != NULL); // Is guaranteed by "if (tail_ == NULL)" above.
+ Message* cur = head_;
+ while (cur->next_ != NULL) {
+ if (cur->next_->dest_port() != Message::kIllegalPort) {
+ // Splice in the new message at the break.
+ msg->next_ = cur->next_;
+ cur->next_ = msg;
+ return;
+ }
+ cur = cur->next_;
+ }
+ // All pending messages are isolate library control messages. Append at
+ // the tail.
+ ASSERT(tail_ == cur);
+ ASSERT(tail_->dest_port() == Message::kIllegalPort);
+ tail_->next_ = msg;
+ tail_ = msg;
+ }
}
}

Powered by Google App Engine
This is Rietveld 408576698