| OLD | NEW | 
|---|
| 1 // Copyright (c) 2012, the Dart project authors.  Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 "platform/assert.h" | 5 #include "platform/assert.h" | 
| 6 #include "vm/message.h" | 6 #include "vm/message.h" | 
| 7 #include "vm/unit_test.h" | 7 #include "vm/unit_test.h" | 
| 8 | 8 | 
| 9 namespace dart { | 9 namespace dart { | 
| 10 | 10 | 
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 123     MonitorLocker ml(sync); | 123     MonitorLocker ml(sync); | 
| 124     ml.Notify(); | 124     ml.Notify(); | 
| 125   } | 125   } | 
| 126 | 126 | 
| 127   // Wait for the other thread to fill the queue a bit. | 127   // Wait for the other thread to fill the queue a bit. | 
| 128   while (!peer.HasMessage()) { | 128   while (!peer.HasMessage()) { | 
| 129     MonitorLocker ml(sync); | 129     MonitorLocker ml(sync); | 
| 130     ml.Wait(5); | 130     ml.Wait(5); | 
| 131   } | 131   } | 
| 132 | 132 | 
| 133   for (int i = 0; i < 3; i++) { | 133   int i = 0; | 
|  | 134   while (i < 3) { | 
| 134     Message* msg = queue->Dequeue(0); | 135     Message* msg = queue->Dequeue(0); | 
| 135     EXPECT(msg != NULL); | 136     // Dequeue(0) can return NULL due to spurious wakeup. | 
| 136     EXPECT_EQ(i + 10, msg->dest_port()); | 137     if (msg != NULL) { | 
| 137     EXPECT_EQ(i + 100, msg->reply_port()); | 138       EXPECT_EQ(i + 10, msg->dest_port()); | 
| 138     EXPECT_EQ(i + 1000, *(reinterpret_cast<int*>(msg->data()))); | 139       EXPECT_EQ(i + 100, msg->reply_port()); | 
| 139     delete msg; | 140       EXPECT_EQ(i + 1000, *(reinterpret_cast<int*>(msg->data()))); | 
|  | 141       delete msg; | 
|  | 142       i++; | 
|  | 143     } | 
| 140   } | 144   } | 
| 141   for (int i = 0; i < 3; i++) { | 145 | 
|  | 146   i = 0; | 
|  | 147   while (i < 3) { | 
| 142     Message* msg = queue->Dequeue(0); | 148     Message* msg = queue->Dequeue(0); | 
| 143     EXPECT(msg != NULL); | 149     // Dequeue(0) can return NULL due to spurious wakeup. | 
| 144     EXPECT_EQ(i + 20, msg->dest_port()); | 150     if (msg != NULL) { | 
| 145     EXPECT_EQ(i + 200, msg->reply_port()); | 151       EXPECT_EQ(i + 20, msg->dest_port()); | 
| 146     EXPECT_EQ(i + 2000, *(reinterpret_cast<int*>(msg->data()))); | 152       EXPECT_EQ(i + 200, msg->reply_port()); | 
| 147     delete msg; | 153       EXPECT_EQ(i + 2000, *(reinterpret_cast<int*>(msg->data()))); | 
|  | 154       delete msg; | 
|  | 155       i++; | 
|  | 156     } | 
| 148   } | 157   } | 
| 149   shared_queue = NULL; | 158   shared_queue = NULL; | 
| 150   delete queue; | 159   delete queue; | 
| 151   Dart::ShutdownIsolate(); | 160   Dart::ShutdownIsolate(); | 
| 152 } | 161 } | 
| 153 | 162 | 
| 154 | 163 | 
| 155 TEST_CASE(MessageQueue_WaitNotify) { | 164 TEST_CASE(MessageQueue_WaitNotify) { | 
| 156   sync = new Monitor(); | 165   sync = new Monitor(); | 
| 157 | 166 | 
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 280   Dart_Port port1 = 1; | 289   Dart_Port port1 = 1; | 
| 281 | 290 | 
| 282   EXPECT(!queue_peer.HasMessage()); | 291   EXPECT(!queue_peer.HasMessage()); | 
| 283   queue.Flush(port1); | 292   queue.Flush(port1); | 
| 284 | 293 | 
| 285   // Queue is still empty. | 294   // Queue is still empty. | 
| 286   EXPECT(!queue_peer.HasMessage()); | 295   EXPECT(!queue_peer.HasMessage()); | 
| 287 } | 296 } | 
| 288 | 297 | 
| 289 }  // namespace dart | 298 }  // namespace dart | 
| OLD | NEW | 
|---|