| 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/unit_test.h" | 7 #include "vm/unit_test.h" |
| 8 | 8 |
| 9 // Custom Isolate Test. | 9 // Custom Isolate Test. |
| 10 // | 10 // |
| 11 // This mid-size test uses the Dart Embedding Api to create a custom | 11 // This mid-size test uses the Dart Embedding Api to create a custom |
| 12 // isolate abstraction. Instead of having a dedicated thread for each | 12 // isolate abstraction. Instead of having a dedicated thread for each |
| 13 // isolate, as is the case normally, this implementation shares a | 13 // isolate, as is the case normally, this implementation shares a |
| 14 // single thread among the isolates using an event queue. | 14 // single thread among the isolates using an event queue. |
| 15 | 15 |
| 16 namespace dart { | 16 namespace dart { |
| 17 | 17 |
| 18 // Only ia32 and x64 can run execution tests. | 18 // Only ia32 and x64 can run execution tests. |
| 19 #if defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64) | 19 #if defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64) |
| 20 | 20 |
| 21 static void native_echo(Dart_NativeArguments args); | 21 static void native_echo(Dart_NativeArguments args); |
| 22 static void CustomIsolateImpl_start(Dart_NativeArguments args); | 22 static void CustomIsolateImpl_start(Dart_NativeArguments args); |
| 23 static Dart_NativeFunction NativeLookup(Dart_Handle name, int argc); | 23 static Dart_NativeFunction NativeLookup(Dart_Handle name, int argc); |
| 24 | 24 |
| 25 | 25 |
| 26 static const char* kCustomIsolateScriptChars = | 26 static const char* kCustomIsolateScriptChars = |
| 27 "import 'dart:async';\n" |
| 27 "import 'dart:isolate';\n" | 28 "import 'dart:isolate';\n" |
| 28 "\n" | 29 "\n" |
| 29 "ReceivePort mainPort;\n" | 30 "ReceivePort mainPort;\n" |
| 30 "\n" | 31 "\n" |
| 31 "echo(arg) native \"native_echo\";\n" | 32 "echo(arg) native \"native_echo\";\n" |
| 32 "\n" | 33 "\n" |
| 33 "class CustomIsolateImpl implements CustomIsolate {\n" | 34 "class CustomIsolateImpl implements CustomIsolate {\n" |
| 34 " CustomIsolateImpl(String entry) : _entry = entry{\n" | 35 " CustomIsolateImpl(String entry) : _entry = entry{\n" |
| 35 " echo('Constructing isolate');\n" | 36 " echo('Constructing isolate');\n" |
| 36 " }\n" | 37 " }\n" |
| (...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 337 OS::Print("-- Finished event loop --\n"); | 338 OS::Print("-- Finished event loop --\n"); |
| 338 EXPECT_STREQ("Received: 43", saved_echo); | 339 EXPECT_STREQ("Received: 43", saved_echo); |
| 339 free(const_cast<char*>(saved_echo)); | 340 free(const_cast<char*>(saved_echo)); |
| 340 | 341 |
| 341 delete event_queue; | 342 delete event_queue; |
| 342 } | 343 } |
| 343 | 344 |
| 344 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). | 345 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). |
| 345 | 346 |
| 346 } // namespace dart | 347 } // namespace dart |
| OLD | NEW |