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

Side by Side Diff: runtime/vm/message.cc

Issue 9420038: Heartbeat implementation of dart:mirrors. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 9 months 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/vm/message.h ('k') | runtime/vm/native_arguments.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 DECLARE_FLAG(bool, trace_isolates); 9 DECLARE_FLAG(bool, trace_isolates);
10 10
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 // We only need to notify if the queue was empty. 103 // We only need to notify if the queue was empty.
104 monitor_.Notify(); 104 monitor_.Notify();
105 } else { 105 } else {
106 ASSERT(tail_[p] != NULL); 106 ASSERT(tail_[p] != NULL);
107 // Append at the tail. 107 // Append at the tail.
108 tail_[p]->next_ = msg; 108 tail_[p]->next_ = msg;
109 tail_[p] = msg; 109 tail_[p] = msg;
110 } 110 }
111 } 111 }
112 112
113
113 Message* MessageQueue::DequeueNoWait() { 114 Message* MessageQueue::DequeueNoWait() {
114 MonitorLocker ml(&monitor_); 115 MonitorLocker ml(&monitor_);
115 return DequeueNoWaitHoldsLock(); 116 return DequeueNoWaitHoldsLock(Message::kFirstPriority);
116 } 117 }
117 118
118 Message* MessageQueue::DequeueNoWaitHoldsLock() { 119
120 Message* MessageQueue::DequeueNoWaitWithPriority(
121 Message::Priority min_priority) {
122 MonitorLocker ml(&monitor_);
123 return DequeueNoWaitHoldsLock(min_priority);
124 }
125
126
127 Message* MessageQueue::DequeueNoWaitHoldsLock(Message::Priority min_priority) {
119 // Look for the highest priority available message. 128 // Look for the highest priority available message.
120 for (int p = Message::kNumPriorities-1; p >= Message::kFirstPriority; p--) { 129 for (int p = Message::kNumPriorities-1; p >= min_priority; p--) {
121 Message* result = head_[p]; 130 Message* result = head_[p];
122 if (result != NULL) { 131 if (result != NULL) {
123 head_[p] = result->next_; 132 head_[p] = result->next_;
124 // The following update to tail_ is not strictly needed. 133 // The following update to tail_ is not strictly needed.
125 if (head_[p] == NULL) { 134 if (head_[p] == NULL) {
126 tail_[p] = NULL; 135 tail_[p] = NULL;
127 } 136 }
128 #if defined(DEBUG) 137 #if defined(DEBUG)
129 result->next_ = result; // Make sure to trigger ASSERT in Enqueue. 138 result->next_ = result; // Make sure to trigger ASSERT in Enqueue.
130 #endif // DEBUG 139 #endif // DEBUG
131 return result; 140 return result;
132 } 141 }
133 } 142 }
134 return NULL; 143 return NULL;
135 } 144 }
136 145
137 146
138 Message* MessageQueue::Dequeue(int64_t millis) { 147 Message* MessageQueue::Dequeue(int64_t millis) {
139 ASSERT(millis >= 0); 148 ASSERT(millis >= 0);
140 MonitorLocker ml(&monitor_); 149 MonitorLocker ml(&monitor_);
141 Message* result = DequeueNoWaitHoldsLock(); 150 Message* result = DequeueNoWaitHoldsLock(Message::kFirstPriority);
142 if (result == NULL) { 151 if (result == NULL) {
143 // No message available at any priority. 152 // No message available at any priority.
144 monitor_.Wait(millis); 153 monitor_.Wait(millis);
145 result = DequeueNoWaitHoldsLock(); 154 result = DequeueNoWaitHoldsLock(Message::kFirstPriority);
146 } 155 }
147 return result; 156 return result;
148 } 157 }
149 158
150 159
151 void MessageQueue::Flush(Dart_Port port) { 160 void MessageQueue::Flush(Dart_Port port) {
152 MonitorLocker ml(&monitor_); 161 MonitorLocker ml(&monitor_);
153 for (int p = Message::kFirstPriority; p < Message::kNumPriorities; p++) { 162 for (int p = Message::kFirstPriority; p < Message::kNumPriorities; p++) {
154 Message* cur = head_[p]; 163 Message* cur = head_[p];
155 Message* prev = NULL; 164 Message* prev = NULL;
(...skipping 28 matching lines...) Expand all
184 while (cur != NULL) { 193 while (cur != NULL) {
185 Message* next = cur->next_; 194 Message* next = cur->next_;
186 delete cur; 195 delete cur;
187 cur = next; 196 cur = next;
188 } 197 }
189 } 198 }
190 } 199 }
191 200
192 201
193 } // namespace dart 202 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/message.h ('k') | runtime/vm/native_arguments.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698