| 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/bootstrap_natives.h" | 6 #include "vm/bootstrap_natives.h" |
| 7 #include "vm/class_finalizer.h" | 7 #include "vm/class_finalizer.h" |
| 8 #include "vm/dart.h" | 8 #include "vm/dart.h" |
| 9 #include "vm/dart_api_impl.h" | 9 #include "vm/dart_api_impl.h" |
| 10 #include "vm/dart_entry.h" | 10 #include "vm/dart_entry.h" |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 return retval; | 161 return retval; |
| 162 } | 162 } |
| 163 | 163 |
| 164 | 164 |
| 165 static bool CreateIsolate(Isolate* parent_isolate, | 165 static bool CreateIsolate(Isolate* parent_isolate, |
| 166 IsolateSpawnState* state, | 166 IsolateSpawnState* state, |
| 167 char** error) { | 167 char** error) { |
| 168 Dart_IsolateCreateCallback callback = Isolate::CreateCallback(); | 168 Dart_IsolateCreateCallback callback = Isolate::CreateCallback(); |
| 169 if (callback == NULL) { | 169 if (callback == NULL) { |
| 170 *error = strdup("Null callback specified for isolate creation\n"); | 170 *error = strdup("Null callback specified for isolate creation\n"); |
| 171 Isolate::SetCurrent(parent_isolate); | |
| 172 return false; | 171 return false; |
| 173 } | 172 } |
| 174 | 173 |
| 175 void* init_data = parent_isolate->init_callback_data(); | 174 void* init_data = parent_isolate->init_callback_data(); |
| 176 Isolate* child_isolate = reinterpret_cast<Isolate*>( | 175 Isolate* child_isolate = reinterpret_cast<Isolate*>( |
| 177 (callback)(state->script_url(), | 176 (callback)(state->script_url(), |
| 178 state->function_name(), | 177 state->function_name(), |
| 179 state->package_root(), | 178 state->package_root(), |
| 180 init_data, | 179 init_data, |
| 181 error)); | 180 error)); |
| 182 if (child_isolate == NULL) { | 181 if (child_isolate == NULL) { |
| 183 Isolate::SetCurrent(parent_isolate); | |
| 184 return false; | 182 return false; |
| 185 } | 183 } |
| 186 if (!state->is_spawn_uri()) { | 184 if (!state->is_spawn_uri()) { |
| 187 // For isolates spawned using the spawnFunction semantics we set | 185 // For isolates spawned using the spawnFunction semantics we set |
| 188 // the origin_id to the origin_id of the parent isolate. | 186 // the origin_id to the origin_id of the parent isolate. |
| 189 child_isolate->set_origin_id(parent_isolate->origin_id()); | 187 child_isolate->set_origin_id(parent_isolate->origin_id()); |
| 190 } | 188 } |
| 191 state->set_isolate(reinterpret_cast<Isolate*>(child_isolate)); | 189 state->set_isolate(reinterpret_cast<Isolate*>(child_isolate)); |
| 192 | |
| 193 Isolate::SetCurrent(parent_isolate); | |
| 194 return true; | 190 return true; |
| 195 } | 191 } |
| 196 | 192 |
| 197 | 193 |
| 198 static void Spawn(Isolate* parent_isolate, IsolateSpawnState* state) { | 194 static void Spawn(Isolate* parent_isolate, IsolateSpawnState* state) { |
| 195 Thread::ExitIsolate(); |
| 199 // Create a new isolate. | 196 // Create a new isolate. |
| 200 char* error = NULL; | 197 char* error = NULL; |
| 201 if (!CreateIsolate(parent_isolate, state, &error)) { | 198 if (!CreateIsolate(parent_isolate, state, &error)) { |
| 199 Thread::EnterIsolate(parent_isolate); |
| 202 delete state; | 200 delete state; |
| 203 const String& msg = String::Handle(String::New(error)); | 201 const String& msg = String::Handle(String::New(error)); |
| 204 free(error); | 202 free(error); |
| 205 ThrowIsolateSpawnException(msg); | 203 ThrowIsolateSpawnException(msg); |
| 206 } | 204 } |
| 207 | 205 Thread::EnterIsolate(parent_isolate); |
| 208 // Start the new isolate if it is already marked as runnable. | 206 // Start the new isolate if it is already marked as runnable. |
| 209 Isolate* spawned_isolate = state->isolate(); | 207 Isolate* spawned_isolate = state->isolate(); |
| 210 MutexLocker ml(spawned_isolate->mutex()); | 208 MutexLocker ml(spawned_isolate->mutex()); |
| 211 spawned_isolate->set_spawn_state(state); | 209 spawned_isolate->set_spawn_state(state); |
| 212 if (spawned_isolate->is_runnable()) { | 210 if (spawned_isolate->is_runnable()) { |
| 213 spawned_isolate->Run(); | 211 spawned_isolate->Run(); |
| 214 } | 212 } |
| 215 } | 213 } |
| 216 | 214 |
| 217 | 215 |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 302 MessageWriter writer(&data, &allocator, false); | 300 MessageWriter writer(&data, &allocator, false); |
| 303 writer.WriteMessage(msg); | 301 writer.WriteMessage(msg); |
| 304 | 302 |
| 305 PortMap::PostMessage(new Message(port.Id(), | 303 PortMap::PostMessage(new Message(port.Id(), |
| 306 data, writer.BytesWritten(), | 304 data, writer.BytesWritten(), |
| 307 Message::kOOBPriority)); | 305 Message::kOOBPriority)); |
| 308 return Object::null(); | 306 return Object::null(); |
| 309 } | 307 } |
| 310 | 308 |
| 311 } // namespace dart | 309 } // namespace dart |
| OLD | NEW |