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

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

Issue 11440035: Optimize the message queue for many active ports with few messages. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Lookup ReceivePort in Dart code Created 8 years 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
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 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 #if defined(DEBUG)
18 ASSERT(head_ == NULL); 17 ASSERT(head_ == NULL);
19 #endif
20 } 18 }
21 19
22 20
23 void MessageQueue::Enqueue(Message* msg) { 21 void MessageQueue::Enqueue(Message* msg) {
24 // Make sure messages are not reused. 22 // Make sure messages are not reused.
25 ASSERT(msg->next_ == NULL); 23 ASSERT(msg->next_ == NULL);
26 if (head_ == NULL) { 24 if (head_ == NULL) {
27 // Only element in the queue. 25 // Only element in the queue.
28 ASSERT(tail_ == NULL); 26 ASSERT(tail_ == NULL);
29 head_ = msg; 27 head_ = msg;
(...skipping 17 matching lines...) Expand all
47 } 45 }
48 #if defined(DEBUG) 46 #if defined(DEBUG)
49 result->next_ = result; // Make sure to trigger ASSERT in Enqueue. 47 result->next_ = result; // Make sure to trigger ASSERT in Enqueue.
50 #endif // DEBUG 48 #endif // DEBUG
51 return result; 49 return result;
52 } 50 }
53 return NULL; 51 return NULL;
54 } 52 }
55 53
56 54
57 void MessageQueue::Flush(Dart_Port port) { 55 void MessageQueue::Clear() {
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() {
82 Message* cur = head_; 56 Message* cur = head_;
83 head_ = NULL; 57 head_ = NULL;
84 tail_ = NULL; 58 tail_ = NULL;
85 while (cur != NULL) { 59 while (cur != NULL) {
86 Message* next = cur->next_; 60 Message* next = cur->next_;
87 delete cur; 61 delete cur;
88 cur = next; 62 cur = next;
89 } 63 }
90 } 64 }
91 65
92 66
93 } // namespace dart 67 } // namespace dart
OLDNEW
« runtime/vm/isolate.cc ('K') | « runtime/vm/message.h ('k') | runtime/vm/message_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698