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

Unified Diff: runtime/vm/message_queue.cc

Issue 9169063: Add support for native ports in the vm. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: '' Created 8 years, 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/vm/message_queue.h ('k') | runtime/vm/message_queue_test.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/message_queue.cc
===================================================================
--- runtime/vm/message_queue.cc (revision 3743)
+++ runtime/vm/message_queue.cc (working copy)
@@ -1,134 +0,0 @@
-// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
-// for details. All rights reserved. Use of this source code is governed by a
-// BSD-style license that can be found in the LICENSE file.
-
-#include "vm/message_queue.h"
-
-namespace dart {
-
-MessageQueue::MessageQueue() {
- for (int p = Message::kFirstPriority; p < Message::kNumPriorities; p++) {
- head_[p] = NULL;
- tail_[p] = NULL;
- }
-}
-
-
-MessageQueue::~MessageQueue() {
- // Ensure that all pending messages have been released.
-#if defined(DEBUG)
- for (int p = Message::kFirstPriority; p < Message::kNumPriorities; p++) {
- ASSERT(head_[p] == NULL);
- }
-#endif
-}
-
-
-void MessageQueue::Enqueue(Message* msg) {
- // TODO(turnidge): Add a scoped locker for monitors which is not a
- // stack resource. This would probably be useful in the platform
- // headers.
- monitor_.Enter();
-
- Message::Priority p = msg->priority();
- // Make sure messages are not reused.
- ASSERT(msg->next_ == NULL);
- if (head_[p] == NULL) {
- // Only element in the queue.
- head_[p] = msg;
- tail_[p] = msg;
-
- // We only need to notify if the queue was empty.
- monitor_.Notify();
- } else {
- ASSERT(tail_[p] != NULL);
- // Append at the tail.
- tail_[p]->next_ = msg;
- tail_[p] = msg;
- }
-
- monitor_.Exit();
-}
-
-Message* MessageQueue::DequeueNoWait() {
- MonitorLocker ml(&monitor_);
- return DequeueNoWaitHoldsLock();
-}
-
-Message* MessageQueue::DequeueNoWaitHoldsLock() {
- // Look for the highest priority available message.
- for (int p = Message::kNumPriorities-1; p >= Message::kFirstPriority; p--) {
- Message* result = head_[p];
- if (result != NULL) {
- head_[p] = result->next_;
- // The following update to tail_ is not strictly needed.
- if (head_[p] == NULL) {
- tail_[p] = NULL;
- }
-#if defined(DEBUG)
- result->next_ = result; // Make sure to trigger ASSERT in Enqueue.
-#endif // DEBUG
- return result;
- }
- }
- return NULL;
-}
-
-
-Message* MessageQueue::Dequeue(int64_t millis) {
- ASSERT(millis >= 0);
- MonitorLocker ml(&monitor_);
-
- Message* result = DequeueNoWaitHoldsLock();
- if (result == NULL) {
- // No message available at any priority.
- ml.Wait(millis);
- result = DequeueNoWaitHoldsLock();
- }
- return result;
-}
-
-
-void MessageQueue::Flush(Dart_Port port) {
- MonitorLocker ml(&monitor_);
- for (int p = Message::kFirstPriority; p < Message::kNumPriorities; p++) {
- Message* cur = head_[p];
- Message* prev = NULL;
- while (cur != NULL) {
- Message* next = cur->next_;
- // If the message matches, then remove it from the queue and delete it.
- if (cur->dest_port() == port) {
- if (prev != NULL) {
- prev->next_ = next;
- } else {
- head_[p] = next;
- }
- delete cur;
- } else {
- // Move prev forward.
- prev = cur;
- }
- // Advance to the next message in the queue.
- cur = next;
- }
- tail_[p] = prev;
- }
-}
-
-
-void MessageQueue::FlushAll() {
- MonitorLocker ml(&monitor_);
- for (int p = Message::kFirstPriority; p < Message::kNumPriorities; p++) {
- Message* cur = head_[p];
- head_[p] = NULL;
- tail_[p] = NULL;
- while (cur != NULL) {
- Message* next = cur->next_;
- delete cur;
- cur = next;
- }
- }
-}
-
-
-} // namespace dart
« no previous file with comments | « runtime/vm/message_queue.h ('k') | runtime/vm/message_queue_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698