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 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
157 *error = zone->PrintToString( | 157 *error = zone->PrintToString( |
158 "Unable to canonicalize uri '%s': no library tag handler found.", | 158 "Unable to canonicalize uri '%s': no library tag handler found.", |
159 uri.ToCString()); | 159 uri.ToCString()); |
160 } | 160 } |
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) { |
siva
2015/04/01 04:08:34
Maybe assert here?
ASSERT(thread->isolate() == NU
koda
2015/04/01 16:05:59
Already done by Thread::EnterIsolate (that's how i
| |
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); | 171 Thread::EnterIsolate(parent_isolate); |
172 return false; | 172 return false; |
173 } | 173 } |
174 | 174 |
175 void* init_data = parent_isolate->init_callback_data(); | 175 void* init_data = parent_isolate->init_callback_data(); |
176 Isolate* child_isolate = reinterpret_cast<Isolate*>( | 176 Isolate* child_isolate = reinterpret_cast<Isolate*>( |
177 (callback)(state->script_url(), | 177 (callback)(state->script_url(), |
178 state->function_name(), | 178 state->function_name(), |
179 state->package_root(), | 179 state->package_root(), |
180 init_data, | 180 init_data, |
181 error)); | 181 error)); |
182 if (child_isolate == NULL) { | 182 if (child_isolate == NULL) { |
183 Isolate::SetCurrent(parent_isolate); | 183 Thread::EnterIsolate(parent_isolate); |
184 return false; | 184 return false; |
185 } | 185 } |
186 if (!state->is_spawn_uri()) { | 186 if (!state->is_spawn_uri()) { |
187 // For isolates spawned using the spawnFunction semantics we set | 187 // For isolates spawned using the spawnFunction semantics we set |
188 // the origin_id to the origin_id of the parent isolate. | 188 // the origin_id to the origin_id of the parent isolate. |
189 child_isolate->set_origin_id(parent_isolate->origin_id()); | 189 child_isolate->set_origin_id(parent_isolate->origin_id()); |
190 } | 190 } |
191 state->set_isolate(reinterpret_cast<Isolate*>(child_isolate)); | 191 state->set_isolate(reinterpret_cast<Isolate*>(child_isolate)); |
192 | 192 |
193 Isolate::SetCurrent(parent_isolate); | 193 Thread::EnterIsolate(parent_isolate); |
194 return true; | 194 return true; |
195 } | 195 } |
196 | 196 |
197 | 197 |
198 static void Spawn(Isolate* parent_isolate, IsolateSpawnState* state) { | 198 static void Spawn(Isolate* parent_isolate, IsolateSpawnState* state) { |
199 Thread::ExitIsolate(); | |
199 // Create a new isolate. | 200 // Create a new isolate. |
200 char* error = NULL; | 201 char* error = NULL; |
201 if (!CreateIsolate(parent_isolate, state, &error)) { | 202 if (!CreateIsolate(parent_isolate, state, &error)) { |
siva
2015/04/01 04:08:34
maybe
Thread::EnterIsolate(parent_isolate);
here
koda
2015/04/01 16:05:59
Done.
| |
202 delete state; | 203 delete state; |
203 const String& msg = String::Handle(String::New(error)); | 204 const String& msg = String::Handle(String::New(error)); |
204 free(error); | 205 free(error); |
205 ThrowIsolateSpawnException(msg); | 206 ThrowIsolateSpawnException(msg); |
206 } | 207 } |
siva
2015/04/01 04:08:34
Thread::EnterIsolate(parent_isolate);
Seems odd t
koda
2015/04/01 16:05:59
This stems from the spec of the API method Dart_Cr
| |
207 | 208 |
208 // Start the new isolate if it is already marked as runnable. | 209 // Start the new isolate if it is already marked as runnable. |
209 Isolate* spawned_isolate = state->isolate(); | 210 Isolate* spawned_isolate = state->isolate(); |
210 MutexLocker ml(spawned_isolate->mutex()); | 211 MutexLocker ml(spawned_isolate->mutex()); |
211 spawned_isolate->set_spawn_state(state); | 212 spawned_isolate->set_spawn_state(state); |
212 if (spawned_isolate->is_runnable()) { | 213 if (spawned_isolate->is_runnable()) { |
213 spawned_isolate->Run(); | 214 spawned_isolate->Run(); |
214 } | 215 } |
215 } | 216 } |
216 | 217 |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
302 MessageWriter writer(&data, &allocator, false); | 303 MessageWriter writer(&data, &allocator, false); |
303 writer.WriteMessage(msg); | 304 writer.WriteMessage(msg); |
304 | 305 |
305 PortMap::PostMessage(new Message(port.Id(), | 306 PortMap::PostMessage(new Message(port.Id(), |
306 data, writer.BytesWritten(), | 307 data, writer.BytesWritten(), |
307 Message::kOOBPriority)); | 308 Message::kOOBPriority)); |
308 return Object::null(); | 309 return Object::null(); |
309 } | 310 } |
310 | 311 |
311 } // namespace dart | 312 } // namespace dart |
OLD | NEW |