| 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.h" | 5 #include "vm/message.h" |
| 6 | 6 |
| 7 namespace dart { | 7 namespace dart { |
| 8 | 8 |
| 9 MessageQueue::MessageQueue() { | 9 MessageQueue::MessageQueue() { |
| 10 head_ = NULL; | 10 head_ = NULL; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 void MessageQueue::Enqueue(Message* msg) { | 22 void MessageQueue::Enqueue(Message* msg) { |
| 23 // Make sure messages are not reused. | 23 // Make sure messages are not reused. |
| 24 ASSERT(msg->next_ == NULL); | 24 ASSERT(msg->next_ == NULL); |
| 25 if (head_ == NULL) { | 25 if (head_ == NULL) { |
| 26 // Only element in the queue. | 26 // Only element in the queue. |
| 27 ASSERT(tail_ == NULL); | 27 ASSERT(tail_ == NULL); |
| 28 head_ = msg; | 28 head_ = msg; |
| 29 tail_ = msg; | 29 tail_ = msg; |
| 30 } else { | 30 } else { |
| 31 ASSERT(tail_ != NULL); | 31 ASSERT(tail_ != NULL); |
| 32 // Append at the tail. | 32 if (msg->priority() == Message::kFirstPriority) { |
| 33 tail_->next_ = msg; | 33 // Set as head element in the queue. |
| 34 tail_ = msg; | 34 msg->next_ = head_; |
| 35 head_ = msg; |
| 36 } else { |
| 37 // Append at the tail. |
| 38 tail_->next_ = msg; |
| 39 tail_ = msg; |
| 40 } |
| 35 } | 41 } |
| 36 } | 42 } |
| 37 | 43 |
| 38 | 44 |
| 39 Message* MessageQueue::Dequeue() { | 45 Message* MessageQueue::Dequeue() { |
| 40 Message* result = head_; | 46 Message* result = head_; |
| 41 if (result != NULL) { | 47 if (result != NULL) { |
| 42 head_ = result->next_; | 48 head_ = result->next_; |
| 43 // The following update to tail_ is not strictly needed. | 49 // The following update to tail_ is not strictly needed. |
| 44 if (head_ == NULL) { | 50 if (head_ == NULL) { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 59 tail_ = NULL; | 65 tail_ = NULL; |
| 60 while (cur != NULL) { | 66 while (cur != NULL) { |
| 61 Message* next = cur->next_; | 67 Message* next = cur->next_; |
| 62 delete cur; | 68 delete cur; |
| 63 cur = next; | 69 cur = next; |
| 64 } | 70 } |
| 65 } | 71 } |
| 66 | 72 |
| 67 | 73 |
| 68 } // namespace dart | 74 } // namespace dart |
| OLD | NEW |