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/isolate.h" | 6 #include "vm/isolate.h" |
7 #include "vm/lockers.h" | 7 #include "vm/lockers.h" |
8 #include "vm/unit_test.h" | 8 #include "vm/unit_test.h" |
9 #include "vm/profiler.h" | 9 #include "vm/profiler.h" |
10 #include "vm/safepoint.h" | 10 #include "vm/safepoint.h" |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 Monitor* monitor = new Monitor(); | 45 Monitor* monitor = new Monitor(); |
46 monitor->Enter(); | 46 monitor->Enter(); |
47 monitor->Exit(); | 47 monitor->Exit(); |
48 EXPECT_EQ(true, monitor->TryEnter()); | 48 EXPECT_EQ(true, monitor->TryEnter()); |
49 monitor->Exit(); | 49 monitor->Exit(); |
50 | 50 |
51 const int kNumAttempts = 5; | 51 const int kNumAttempts = 5; |
52 int attempts = 0; | 52 int attempts = 0; |
53 while (attempts < kNumAttempts) { | 53 while (attempts < kNumAttempts) { |
54 MonitorLocker ml(monitor); | 54 MonitorLocker ml(monitor); |
55 int64_t start = OS::GetCurrentTimeMillis(); | 55 int64_t start = OS::GetCurrentMonotonicMicros(); |
56 int64_t wait_time = 2017; | 56 int64_t wait_time = 2017; |
57 Monitor::WaitResult wait_result = ml.Wait(wait_time); | 57 Monitor::WaitResult wait_result = ml.Wait(wait_time); |
58 int64_t stop = OS::GetCurrentTimeMillis(); | 58 int64_t stop = OS::GetCurrentMonotonicMicros(); |
59 | 59 |
60 // We expect to be timing out here. | 60 // We expect to be timing out here. |
61 EXPECT_EQ(Monitor::kTimedOut, wait_result); | 61 EXPECT_EQ(Monitor::kTimedOut, wait_result); |
62 | 62 |
63 // Check whether this attempt falls within the exptected time limits. | 63 // Check whether this attempt falls within the exptected time limits. |
64 int64_t wakeup_time = stop - start; | 64 int64_t wakeup_time = (stop - start) / kMicrosecondsPerMillisecond; |
65 OS::Print("wakeup_time: %" Pd64 "\n", wakeup_time); | 65 OS::Print("wakeup_time: %" Pd64 "\n", wakeup_time); |
66 const int kAcceptableTimeJitter = 20; // Measured in milliseconds. | 66 const int kAcceptableTimeJitter = 20; // Measured in milliseconds. |
67 const int kAcceptableWakeupDelay = 150; // Measured in milliseconds. | 67 const int kAcceptableWakeupDelay = 150; // Measured in milliseconds. |
68 if (((wait_time - kAcceptableTimeJitter) <= wakeup_time) && | 68 if (((wait_time - kAcceptableTimeJitter) <= wakeup_time) && |
69 (wakeup_time <= (wait_time + kAcceptableWakeupDelay))) { | 69 (wakeup_time <= (wait_time + kAcceptableWakeupDelay))) { |
70 break; | 70 break; |
71 } | 71 } |
72 | 72 |
73 // Record the attempt. | 73 // Record the attempt. |
74 attempts++; | 74 attempts++; |
(...skipping 717 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
792 TransitionVMToBlocked transition(thread); | 792 TransitionVMToBlocked transition(thread); |
793 MonitorLocker ml(&done_monitor); | 793 MonitorLocker ml(&done_monitor); |
794 if (done) { | 794 if (done) { |
795 break; | 795 break; |
796 } | 796 } |
797 } | 797 } |
798 } | 798 } |
799 } | 799 } |
800 | 800 |
801 } // namespace dart | 801 } // namespace dart |
OLD | NEW |