OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. | 2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 WorkerThread* m_thread; | 241 WorkerThread* m_thread; |
242 }; | 242 }; |
243 | 243 |
244 WorkerThread::WorkerThread(WorkerLoaderProxy& workerLoaderProxy, WorkerReporting
Proxy& workerReportingProxy, PassOwnPtrWillBeRawPtr<WorkerThreadStartupData> sta
rtupData) | 244 WorkerThread::WorkerThread(WorkerLoaderProxy& workerLoaderProxy, WorkerReporting
Proxy& workerReportingProxy, PassOwnPtrWillBeRawPtr<WorkerThreadStartupData> sta
rtupData) |
245 : m_terminated(false) | 245 : m_terminated(false) |
246 , m_workerLoaderProxy(workerLoaderProxy) | 246 , m_workerLoaderProxy(workerLoaderProxy) |
247 , m_workerReportingProxy(workerReportingProxy) | 247 , m_workerReportingProxy(workerReportingProxy) |
248 , m_startupData(startupData) | 248 , m_startupData(startupData) |
249 , m_shutdownEvent(adoptPtr(blink::Platform::current()->createWaitableEvent()
)) | 249 , m_shutdownEvent(adoptPtr(blink::Platform::current()->createWaitableEvent()
)) |
250 , m_terminationEvent(adoptPtr(blink::Platform::current()->createWaitableEven
t())) | 250 , m_terminationEvent(adoptPtr(blink::Platform::current()->createWaitableEven
t())) |
| 251 , m_isolate(nullptr) |
251 { | 252 { |
252 MutexLocker lock(threadSetMutex()); | 253 MutexLocker lock(threadSetMutex()); |
253 workerThreads().add(this); | 254 workerThreads().add(this); |
254 } | 255 } |
255 | 256 |
256 WorkerThread::~WorkerThread() | 257 WorkerThread::~WorkerThread() |
257 { | 258 { |
258 MutexLocker lock(threadSetMutex()); | 259 MutexLocker lock(threadSetMutex()); |
259 ASSERT(workerThreads().contains(this)); | 260 ASSERT(workerThreads().contains(this)); |
260 workerThreads().remove(this); | 261 workerThreads().remove(this); |
261 } | 262 } |
262 | 263 |
263 void WorkerThread::start() | 264 void WorkerThread::start() |
264 { | 265 { |
265 if (m_thread) | 266 if (m_thread) |
266 return; | 267 return; |
267 | 268 |
268 m_thread = WebThreadSupportingGC::create("WebCore: Worker"); | 269 m_thread = createWebThreadSupportingGC(); |
269 m_thread->postTask(new Task(WTF::bind(&WorkerThread::initialize, this))); | 270 m_thread->postTask(new Task(WTF::bind(&WorkerThread::initialize, this))); |
270 } | 271 } |
271 | 272 |
272 void WorkerThread::interruptAndDispatchInspectorCommands() | 273 void WorkerThread::interruptAndDispatchInspectorCommands() |
273 { | 274 { |
274 MutexLocker locker(m_workerInspectorControllerMutex); | 275 MutexLocker locker(m_workerInspectorControllerMutex); |
275 if (m_workerInspectorController) | 276 if (m_workerInspectorController) |
276 m_workerInspectorController->interruptAndDispatchInspectorCommands(); | 277 m_workerInspectorController->interruptAndDispatchInspectorCommands(); |
277 } | 278 } |
278 | 279 |
279 PlatformThreadId WorkerThread::platformThreadId() const | 280 PlatformThreadId WorkerThread::platformThreadId() const |
280 { | 281 { |
281 if (!m_thread) | 282 if (!m_thread) |
282 return 0; | 283 return 0; |
283 return m_thread->platformThread().threadId(); | 284 return m_thread->platformThread().threadId(); |
284 } | 285 } |
285 | 286 |
| 287 v8::Isolate* WorkerThread::isolate() const |
| 288 { |
| 289 ASSERT(isCurrentThread()); |
| 290 return m_isolate; |
| 291 } |
| 292 |
286 void WorkerThread::initialize() | 293 void WorkerThread::initialize() |
287 { | 294 { |
288 KURL scriptURL = m_startupData->m_scriptURL; | 295 KURL scriptURL = m_startupData->m_scriptURL; |
289 String sourceCode = m_startupData->m_sourceCode; | 296 String sourceCode = m_startupData->m_sourceCode; |
290 WorkerThreadStartMode startMode = m_startupData->m_startMode; | 297 WorkerThreadStartMode startMode = m_startupData->m_startMode; |
291 | 298 |
292 { | 299 { |
293 MutexLocker lock(m_threadCreationMutex); | 300 MutexLocker lock(m_threadCreationMutex); |
294 | 301 |
295 // The worker was terminated before the thread had a chance to run. | 302 // The worker was terminated before the thread had a chance to run. |
296 if (m_terminated) { | 303 if (m_terminated) { |
297 // Notify the proxy that the WorkerGlobalScope has been disposed of. | 304 // Notify the proxy that the WorkerGlobalScope has been disposed of. |
298 // This can free this thread object, hence it must not be touched af
terwards. | 305 // This can free this thread object, hence it must not be touched af
terwards. |
299 m_workerReportingProxy.workerThreadTerminated(); | 306 m_workerReportingProxy.workerThreadTerminated(); |
300 return; | 307 return; |
301 } | 308 } |
302 | 309 |
303 m_microtaskRunner = adoptPtr(new MicrotaskRunner); | 310 m_microtaskRunner = adoptPtr(new MicrotaskRunner); |
304 m_thread->addTaskObserver(m_microtaskRunner.get()); | 311 m_thread->addTaskObserver(m_microtaskRunner.get()); |
305 m_thread->attachGC(); | 312 m_thread->attachGC(); |
| 313 |
| 314 m_isolate = initializeIsolate(); |
| 315 |
306 m_workerGlobalScope = createWorkerGlobalScope(m_startupData.release()); | 316 m_workerGlobalScope = createWorkerGlobalScope(m_startupData.release()); |
307 | 317 |
308 m_sharedTimer = adoptPtr(new WorkerSharedTimer(this)); | 318 m_sharedTimer = adoptPtr(new WorkerSharedTimer(this)); |
309 PlatformThreadData::current().threadTimers().setSharedTimer(m_sharedTime
r.get()); | 319 PlatformThreadData::current().threadTimers().setSharedTimer(m_sharedTime
r.get()); |
310 } | 320 } |
311 | 321 |
312 // The corresponding call to didStopWorkerRunLoop is in | 322 // The corresponding call to didStopWorkerRunLoop is in |
313 // ~WorkerScriptController. | 323 // ~WorkerScriptController. |
314 blink::Platform::current()->didStartWorkerRunLoop(blink::WebWorkerRunLoop(th
is)); | 324 blink::Platform::current()->didStartWorkerRunLoop(blink::WebWorkerRunLoop(th
is)); |
315 | 325 |
316 // Notify proxy that a new WorkerGlobalScope has been created and started. | 326 // Notify proxy that a new WorkerGlobalScope has been created and started. |
317 m_workerReportingProxy.workerGlobalScopeStarted(m_workerGlobalScope.get()); | 327 m_workerReportingProxy.workerGlobalScopeStarted(m_workerGlobalScope.get()); |
318 | 328 |
319 WorkerScriptController* script = m_workerGlobalScope->script(); | 329 WorkerScriptController* script = m_workerGlobalScope->script(); |
320 if (!script->isExecutionForbidden()) | 330 if (!script->isExecutionForbidden()) |
321 script->initializeContextIfNeeded(); | 331 script->initializeContextIfNeeded(); |
322 InspectorInstrumentation::willEvaluateWorkerScript(workerGlobalScope(), star
tMode); | 332 InspectorInstrumentation::willEvaluateWorkerScript(workerGlobalScope(), star
tMode); |
323 bool success = script->evaluate(ScriptSourceCode(sourceCode, scriptURL)); | 333 bool success = script->evaluate(ScriptSourceCode(sourceCode, scriptURL)); |
324 m_workerGlobalScope->didEvaluateWorkerScript(); | 334 m_workerGlobalScope->didEvaluateWorkerScript(); |
325 m_workerReportingProxy.didEvaluateWorkerScript(success); | 335 m_workerReportingProxy.didEvaluateWorkerScript(success); |
326 | 336 |
327 postInitialize(); | 337 postInitialize(); |
328 | 338 |
329 postDelayedTask(createSameThreadTask(&WorkerThread::idleHandler, this), kSho
rtIdleHandlerDelayMs); | 339 postDelayedTask(createSameThreadTask(&WorkerThread::idleHandler, this), kSho
rtIdleHandlerDelayMs); |
330 } | 340 } |
331 | 341 |
| 342 v8::Isolate* WorkerThread::initializeIsolate() |
| 343 { |
| 344 ASSERT(isCurrentThread()); |
| 345 v8::Isolate* isolate = V8PerIsolateData::initialize(); |
| 346 V8Initializer::initializeWorker(isolate); |
| 347 return isolate; |
| 348 } |
| 349 |
| 350 PassOwnPtr<WebThreadSupportingGC> WorkerThread::createWebThreadSupportingGC() |
| 351 { |
| 352 return WebThreadSupportingGC::create("WebCore: Worker"); |
| 353 } |
| 354 |
332 void WorkerThread::cleanup() | 355 void WorkerThread::cleanup() |
333 { | 356 { |
334 | 357 |
335 // This should be called before we start the shutdown procedure. | 358 // This should be called before we start the shutdown procedure. |
336 workerReportingProxy().willDestroyWorkerGlobalScope(); | 359 workerReportingProxy().willDestroyWorkerGlobalScope(); |
337 | 360 |
338 // The below assignment will destroy the context, which will in turn notify
messaging proxy. | 361 // The below assignment will destroy the context, which will in turn notify
messaging proxy. |
339 // We cannot let any objects survive past thread exit, because no other thre
ad will run GC or otherwise destroy them. | 362 // We cannot let any objects survive past thread exit, because no other thre
ad will run GC or otherwise destroy them. |
340 // If Oilpan is enabled, we detach of the context/global scope, with the fin
al heap cleanup below sweeping it out. | 363 // If Oilpan is enabled, we detach of the context/global scope, with the fin
al heap cleanup below sweeping it out. |
341 #if !ENABLE(OILPAN) | 364 #if !ENABLE(OILPAN) |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
532 InspectorInstrumentation::didLeaveNestedRunLoop(m_workerGlobalScope.get()); | 555 InspectorInstrumentation::didLeaveNestedRunLoop(m_workerGlobalScope.get()); |
533 } | 556 } |
534 | 557 |
535 void WorkerThread::setWorkerInspectorController(WorkerInspectorController* worke
rInspectorController) | 558 void WorkerThread::setWorkerInspectorController(WorkerInspectorController* worke
rInspectorController) |
536 { | 559 { |
537 MutexLocker locker(m_workerInspectorControllerMutex); | 560 MutexLocker locker(m_workerInspectorControllerMutex); |
538 m_workerInspectorController = workerInspectorController; | 561 m_workerInspectorController = workerInspectorController; |
539 } | 562 } |
540 | 563 |
541 } // namespace blink | 564 } // namespace blink |
OLD | NEW |