Chromium Code Reviews| 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 "include/dart_api.h" | 5 #include "include/dart_api.h" |
| 6 | 6 |
| 7 #include "vm/assert.h" | 7 #include "vm/assert.h" |
| 8 #include "vm/dart_api_impl.h" | 8 #include "vm/dart_api_impl.h" |
| 9 #include "vm/dart_api_state.h" | 9 #include "vm/dart_api_state.h" |
| 10 #include "vm/thread.h" | 10 #include "vm/thread.h" |
| (...skipping 3028 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3039 sync->Enter(); | 3039 sync->Enter(); |
| 3040 shared_isolate = NULL; | 3040 shared_isolate = NULL; |
| 3041 sync->Notify(); | 3041 sync->Notify(); |
| 3042 sync->Exit(); | 3042 sync->Exit(); |
| 3043 } | 3043 } |
| 3044 | 3044 |
| 3045 | 3045 |
| 3046 // This callback handles isolate interrupts for the IsolateInterrupt | 3046 // This callback handles isolate interrupts for the IsolateInterrupt |
| 3047 // test. It ignores the first two interrupts and throws an exception | 3047 // test. It ignores the first two interrupts and throws an exception |
| 3048 // on the third interrupt. | 3048 // on the third interrupt. |
| 3049 const int kInterruptCount = 10; | |
| 3049 static int interrupt_count = 0; | 3050 static int interrupt_count = 0; |
| 3050 static bool IsolateInterruptTestCallback() { | 3051 static bool IsolateInterruptTestCallback() { |
| 3051 OS::Print(" ========== Interrupt callback called #%d\n", interrupt_count + 1); | 3052 OS::Print(" ========== Interrupt callback called #%d\n", interrupt_count + 1); |
| 3052 { | 3053 { |
| 3053 MonitorLocker ml(sync); | 3054 MonitorLocker ml(sync); |
| 3054 interrupt_count++; | 3055 interrupt_count++; |
| 3055 ml.Notify(); | 3056 ml.Notify(); |
| 3056 } | 3057 } |
| 3057 if (interrupt_count >= 3) { | 3058 if (interrupt_count == kInterruptCount) { |
| 3058 Dart_EnterScope(); | 3059 Dart_EnterScope(); |
| 3059 Dart_Handle lib = Dart_LookupLibrary(Dart_NewString(TestCase::url())); | 3060 Dart_Handle lib = Dart_LookupLibrary(Dart_NewString(TestCase::url())); |
| 3060 EXPECT_VALID(lib); | 3061 EXPECT_VALID(lib); |
| 3061 Dart_Handle exc = Dart_NewString("foo"); | 3062 Dart_Handle exc = Dart_NewString("foo"); |
| 3062 EXPECT_VALID(exc); | 3063 EXPECT_VALID(exc); |
| 3063 Dart_Handle result = Dart_ThrowException(exc); | 3064 Dart_Handle result = Dart_ThrowException(exc); |
| 3064 EXPECT_VALID(result); | 3065 EXPECT_VALID(result); |
| 3065 UNREACHABLE(); // Dart_ThrowException only returns if it gets an error. | 3066 UNREACHABLE(); // Dart_ThrowException only returns if it gets an error. |
| 3066 return false; | 3067 return false; |
| 3067 } | 3068 } |
| 3069 ASSERT(interrupt_count < kInterruptCount); | |
| 3068 return true; | 3070 return true; |
| 3069 } | 3071 } |
| 3070 | 3072 |
| 3071 | 3073 |
| 3072 TEST_CASE(IsolateInterrupt) { | 3074 TEST_CASE(IsolateInterrupt) { |
| 3073 Dart_IsolateInterruptCallback saved = Isolate::InterruptCallback(); | 3075 Dart_IsolateInterruptCallback saved = Isolate::InterruptCallback(); |
| 3074 Isolate::SetInterruptCallback(IsolateInterruptTestCallback); | 3076 Isolate::SetInterruptCallback(IsolateInterruptTestCallback); |
| 3075 | 3077 |
| 3076 sync = new Monitor(); | 3078 sync = new Monitor(); |
| 3077 Thread* thread = new Thread(BusyLoop_start, 0); | 3079 Thread* thread = new Thread(BusyLoop_start, 0); |
| 3078 EXPECT(thread != NULL); | 3080 EXPECT(thread != NULL); |
| 3079 | 3081 |
| 3080 { | 3082 { |
| 3081 MonitorLocker ml(sync); | 3083 MonitorLocker ml(sync); |
| 3082 // Wait for the other isolate to enter main. | 3084 // Wait for the other isolate to enter main. |
| 3083 while (!main_entered) { | 3085 while (!main_entered) { |
| 3084 ml.Wait(); | 3086 ml.Wait(); |
| 3085 } | 3087 } |
| 3086 } | 3088 } |
| 3087 | 3089 |
| 3088 // Send three interrupts to the other isolate. The first two allow | 3090 // Send a number of interrupts to the other isolate. All but the |
| 3089 // execution to continue. The third causes an exception in the | 3091 // last allow execution to continue. The last causes an exception in |
| 3090 // isolate. | 3092 // the isolate. |
| 3091 for (int i = 0; i < 3; i++) { | 3093 for (int i = 0; i < kInterruptCount; i++) { |
| 3094 OS::Sleep(i + 1); | |
| 3092 Dart_InterruptIsolate(shared_isolate); | 3095 Dart_InterruptIsolate(shared_isolate); |
| 3093 { | 3096 { |
| 3094 MonitorLocker ml(sync); | 3097 MonitorLocker ml(sync); |
| 3095 // Wait for interrupt_count to be increased. | 3098 // Wait for interrupt_count to be increased. |
| 3096 while (interrupt_count == i) { | 3099 while (interrupt_count == i) { |
| 3097 ml.Wait(); | 3100 ml.Wait(); |
| 3098 } | 3101 } |
| 3099 OS::Print(" ========== Interrupt processed #%d\n", interrupt_count); | 3102 OS::Print(" ========== Interrupt processed #%d\n", interrupt_count); |
| 3100 } | 3103 } |
| 3104 // Space out the interrupts a bit. | |
|
Ivan Posva
2011/12/22 08:23:10
Comment could have moved with the corresponding co
Søren Gjesse
2011/12/22 15:33:45
Done, http://codereview.chromium.org/9025014/.
| |
| 3101 } | 3105 } |
| 3102 | 3106 |
| 3103 { | 3107 { |
| 3104 MonitorLocker ml(sync); | 3108 MonitorLocker ml(sync); |
| 3105 // Wait for our isolate to finish. | 3109 // Wait for our isolate to finish. |
| 3106 while (shared_isolate != NULL) { | 3110 while (shared_isolate != NULL) { |
| 3107 ml.Wait(); | 3111 ml.Wait(); |
| 3108 } | 3112 } |
| 3109 } | 3113 } |
| 3110 | 3114 |
| 3111 // We should have received 3 interrupts. | 3115 // We should have received the expected number of interrupts. |
| 3112 EXPECT_EQ(3, interrupt_count); | 3116 EXPECT_EQ(kInterruptCount, interrupt_count); |
| 3113 | 3117 |
| 3114 // Give the spawned thread enough time to properly exit. | 3118 // Give the spawned thread enough time to properly exit. |
| 3115 Isolate::SetInterruptCallback(saved); | 3119 Isolate::SetInterruptCallback(saved); |
| 3116 } | 3120 } |
| 3117 | 3121 |
| 3118 #endif // TARGET_ARCH_IA32. | 3122 #endif // TARGET_ARCH_IA32. |
| 3119 | 3123 |
| 3120 } // namespace dart | 3124 } // namespace dart |
| OLD | NEW |