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

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: Merge with caching changes. Created 7 years, 12 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/message_handler.cc » ('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 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) 17 Clear();
18 ASSERT(head_ == NULL); 18 ASSERT(head_ == NULL);
19 #endif
20 } 19 }
21 20
22 21
23 void MessageQueue::Enqueue(Message* msg) { 22 void MessageQueue::Enqueue(Message* msg) {
24 // Make sure messages are not reused. 23 // Make sure messages are not reused.
25 ASSERT(msg->next_ == NULL); 24 ASSERT(msg->next_ == NULL);
26 if (head_ == NULL) { 25 if (head_ == NULL) {
27 // Only element in the queue. 26 // Only element in the queue.
28 ASSERT(tail_ == NULL); 27 ASSERT(tail_ == NULL);
29 head_ = msg; 28 head_ = msg;
(...skipping 17 matching lines...) Expand all
47 } 46 }
48 #if defined(DEBUG) 47 #if defined(DEBUG)
49 result->next_ = result; // Make sure to trigger ASSERT in Enqueue. 48 result->next_ = result; // Make sure to trigger ASSERT in Enqueue.
50 #endif // DEBUG 49 #endif // DEBUG
51 return result; 50 return result;
52 } 51 }
53 return NULL; 52 return NULL;
54 } 53 }
55 54
56 55
57 void MessageQueue::Flush(Dart_Port port) { 56 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_; 57 Message* cur = head_;
83 head_ = NULL; 58 head_ = NULL;
84 tail_ = NULL; 59 tail_ = NULL;
85 while (cur != NULL) { 60 while (cur != NULL) {
86 Message* next = cur->next_; 61 Message* next = cur->next_;
87 delete cur; 62 delete cur;
88 cur = next; 63 cur = next;
89 } 64 }
90 } 65 }
91 66
92 67
93 } // namespace dart 68 } // namespace dart
OLDNEW
« no previous file with comments | « 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