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_queue.h" | 5 #include "vm/message_queue.h" |
6 | 6 |
7 namespace dart { | 7 namespace dart { |
8 | 8 |
9 MessageQueue::~MessageQueue() { | 9 MessageQueue::~MessageQueue() { |
10 // Ensure that all pending messages have been released. | 10 // Ensure that all pending messages have been released. |
(...skipping 22 matching lines...) Expand all Loading... | |
33 tail_ = msg; | 33 tail_ = msg; |
34 } | 34 } |
35 | 35 |
36 monitor_.Exit(); | 36 monitor_.Exit(); |
37 } | 37 } |
38 | 38 |
39 | 39 |
40 PortMessage* MessageQueue::Dequeue(int64_t millis) { | 40 PortMessage* MessageQueue::Dequeue(int64_t millis) { |
41 MonitorLocker ml(&monitor_); | 41 MonitorLocker ml(&monitor_); |
42 PortMessage* result = head_; | 42 PortMessage* result = head_; |
43 if (result == NULL) { | 43 // Wait may wake up prematurely, so we need to loop until result != NULL |
siva
2011/10/21 21:18:33
// Wait for message to be enqueued or timeout.
| |
44 while (result == NULL) { | |
44 ml.Wait(millis); | 45 ml.Wait(millis); |
45 result = head_; | 46 result = head_; |
47 // If there's a time-out the caller must check for NULL anyway. | |
48 if (0 < millis) | |
49 break; | |
siva
2011/10/21 21:18:33
This is not correct, if a spurious wake up happens
jrgfogh
2011/10/24 09:20:42
I know. Neither way is strictly correct. My code h
| |
46 } | 50 } |
47 if (result != NULL) { | 51 if (result != NULL) { |
48 head_ = result->next_; | 52 head_ = result->next_; |
49 // The following update to tail_ is not strictly needed. | 53 // The following update to tail_ is not strictly needed. |
50 if (head_ == NULL) { | 54 if (head_ == NULL) { |
51 tail_ = NULL; | 55 tail_ = NULL; |
52 } | 56 } |
53 #if DEBUG | 57 #if DEBUG |
54 result->next_ = result; // Make sure to trigger ASSERT in Enqueue. | 58 result->next_ = result; // Make sure to trigger ASSERT in Enqueue. |
55 #endif // DEBUG | 59 #endif // DEBUG |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
90 tail_ = NULL; | 94 tail_ = NULL; |
91 while (cur != NULL) { | 95 while (cur != NULL) { |
92 PortMessage* next = cur->next_; | 96 PortMessage* next = cur->next_; |
93 delete cur; | 97 delete cur; |
94 cur = next; | 98 cur = next; |
95 } | 99 } |
96 } | 100 } |
97 | 101 |
98 | 102 |
99 } // namespace dart | 103 } // namespace dart |
OLD | NEW |