Chromium Code Reviews| 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; |
| + } |
| } |
| } |