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; |
11 tail_ = NULL; | 11 tail_ = NULL; |
12 } | 12 } |
13 | 13 |
14 | 14 |
15 MessageQueue::~MessageQueue() { | 15 MessageQueue::~MessageQueue() { |
16 // Ensure that all pending messages have been released. | 16 // Ensure that all pending messages have been released. |
17 Clear(); | 17 #if defined(DEBUG) |
18 ASSERT(head_ == NULL); | 18 ASSERT(head_ == NULL); |
| 19 #endif |
19 } | 20 } |
20 | 21 |
21 | 22 |
22 void MessageQueue::Enqueue(Message* msg) { | 23 void MessageQueue::Enqueue(Message* msg) { |
23 // Make sure messages are not reused. | 24 // Make sure messages are not reused. |
24 ASSERT(msg->next_ == NULL); | 25 ASSERT(msg->next_ == NULL); |
25 if (head_ == NULL) { | 26 if (head_ == NULL) { |
26 // Only element in the queue. | 27 // Only element in the queue. |
27 ASSERT(tail_ == NULL); | 28 ASSERT(tail_ == NULL); |
28 head_ = msg; | 29 head_ = msg; |
(...skipping 17 matching lines...) Expand all Loading... |
46 } | 47 } |
47 #if defined(DEBUG) | 48 #if defined(DEBUG) |
48 result->next_ = result; // Make sure to trigger ASSERT in Enqueue. | 49 result->next_ = result; // Make sure to trigger ASSERT in Enqueue. |
49 #endif // DEBUG | 50 #endif // DEBUG |
50 return result; | 51 return result; |
51 } | 52 } |
52 return NULL; | 53 return NULL; |
53 } | 54 } |
54 | 55 |
55 | 56 |
56 void MessageQueue::Clear() { | 57 void MessageQueue::Flush(Dart_Port port) { |
| 58 Message* cur = head_; |
| 59 Message* prev = NULL; |
| 60 while (cur != NULL) { |
| 61 Message* next = cur->next_; |
| 62 // If the message matches, then remove it from the queue and delete it. |
| 63 if (cur->dest_port() == port) { |
| 64 if (prev != NULL) { |
| 65 prev->next_ = next; |
| 66 } else { |
| 67 head_ = next; |
| 68 } |
| 69 delete cur; |
| 70 } else { |
| 71 // Move prev forward. |
| 72 prev = cur; |
| 73 } |
| 74 // Advance to the next message in the queue. |
| 75 cur = next; |
| 76 } |
| 77 tail_ = prev; |
| 78 } |
| 79 |
| 80 |
| 81 void MessageQueue::FlushAll() { |
57 Message* cur = head_; | 82 Message* cur = head_; |
58 head_ = NULL; | 83 head_ = NULL; |
59 tail_ = NULL; | 84 tail_ = NULL; |
60 while (cur != NULL) { | 85 while (cur != NULL) { |
61 Message* next = cur->next_; | 86 Message* next = cur->next_; |
62 delete cur; | 87 delete cur; |
63 cur = next; | 88 cur = next; |
64 } | 89 } |
65 } | 90 } |
66 | 91 |
67 | 92 |
68 } // namespace dart | 93 } // namespace dart |
OLD | NEW |