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 #include "vm/port.h" | 7 #include "vm/port.h" |
8 | 8 |
9 namespace dart { | 9 namespace dart { |
10 | 10 |
(...skipping 13 matching lines...) Expand all Loading... | |
24 } | 24 } |
25 | 25 |
26 | 26 |
27 MessageQueue::~MessageQueue() { | 27 MessageQueue::~MessageQueue() { |
28 // Ensure that all pending messages have been released. | 28 // Ensure that all pending messages have been released. |
29 Clear(); | 29 Clear(); |
30 ASSERT(head_ == NULL); | 30 ASSERT(head_ == NULL); |
31 } | 31 } |
32 | 32 |
33 | 33 |
34 void MessageQueue::Enqueue(Message* msg) { | 34 void MessageQueue::Enqueue(Message* msg, bool before_events) { |
35 // Make sure messages are not reused. | 35 // Make sure messages are not reused. |
36 ASSERT(msg->next_ == NULL); | 36 ASSERT(msg->next_ == NULL); |
37 if (head_ == NULL) { | 37 if (!before_events) { |
38 // Only element in the queue. | 38 if (head_ == NULL) { |
39 ASSERT(tail_ == NULL); | 39 // Only element in the queue. |
40 head_ = msg; | 40 ASSERT(tail_ == NULL); |
41 tail_ = msg; | 41 head_ = msg; |
42 tail_ = msg; | |
43 } else { | |
44 ASSERT(tail_ != NULL); | |
45 // Append at the tail. | |
46 tail_->next_ = msg; | |
47 tail_ = msg; | |
48 } | |
42 } else { | 49 } else { |
43 ASSERT(tail_ != NULL); | 50 ASSERT(msg->dest_port() == Message::kIllegalPort); |
44 // Append at the tail. | 51 if (tail_ == NULL) { |
45 tail_->next_ = msg; | 52 ASSERT(head_ == NULL); |
46 tail_ = msg; | 53 head_ = msg; |
54 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.
| |
55 } else if (head_->dest_port() != Message::kIllegalPort) { | |
56 msg->next_ = head_; | |
57 head_ = msg; | |
58 } else { | |
59 ASSERT(head_ != NULL); // Is guaranteed by "if (tail_ == NULL)" above. | |
60 Message* cur = head_; | |
61 while (cur->next_ != NULL) { | |
62 if (cur->next_->dest_port() != Message::kIllegalPort) { | |
63 // Splice in the new message at the break. | |
64 msg->next_ = cur->next_; | |
65 cur->next_ = msg; | |
66 return; | |
67 } | |
68 cur = cur->next_; | |
69 } | |
70 // All pending messages are isolate library control messages. Append at | |
71 // the tail. | |
72 ASSERT(tail_ == cur); | |
73 ASSERT(tail_->dest_port() == Message::kIllegalPort); | |
74 tail_->next_ = msg; | |
75 tail_ = msg; | |
76 } | |
47 } | 77 } |
48 } | 78 } |
49 | 79 |
50 | 80 |
51 Message* MessageQueue::Dequeue() { | 81 Message* MessageQueue::Dequeue() { |
52 Message* result = head_; | 82 Message* result = head_; |
53 if (result != NULL) { | 83 if (result != NULL) { |
54 head_ = result->next_; | 84 head_ = result->next_; |
55 // The following update to tail_ is not strictly needed. | 85 // The following update to tail_ is not strictly needed. |
56 if (head_ == NULL) { | 86 if (head_ == NULL) { |
(...skipping 18 matching lines...) Expand all Loading... | |
75 PortMap::PostMessage(cur); | 105 PortMap::PostMessage(cur); |
76 } else { | 106 } else { |
77 delete cur; | 107 delete cur; |
78 } | 108 } |
79 cur = next; | 109 cur = next; |
80 } | 110 } |
81 } | 111 } |
82 | 112 |
83 | 113 |
84 } // namespace dart | 114 } // namespace dart |
OLD | NEW |