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 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
233 MutexLocker locker(m_workerInspectorControllerMutex); | 233 MutexLocker locker(m_workerInspectorControllerMutex); |
234 if (m_workerInspectorController) | 234 if (m_workerInspectorController) |
235 m_workerInspectorController->interruptAndDispatchInspectorCommands(); | 235 m_workerInspectorController->interruptAndDispatchInspectorCommands(); |
236 } | 236 } |
237 | 237 |
238 void WorkerThread::initialize() | 238 void WorkerThread::initialize() |
239 { | 239 { |
240 KURL scriptURL = m_startupData->m_scriptURL; | 240 KURL scriptURL = m_startupData->m_scriptURL; |
241 String sourceCode = m_startupData->m_sourceCode; | 241 String sourceCode = m_startupData->m_sourceCode; |
242 WorkerThreadStartMode startMode = m_startupData->m_startMode; | 242 WorkerThreadStartMode startMode = m_startupData->m_startMode; |
243 m_microtaskRunner = adoptPtr(new MicrotaskRunner); | |
244 m_thread->addTaskObserver(m_microtaskRunner.get()); | |
horo
2014/08/13 03:32:29
Why do you remove these lines?
haraken
2014/08/13 04:13:42
These lines are moved to after the 'if(m_terminate
| |
245 | 243 |
246 { | 244 { |
247 MutexLocker lock(m_threadCreationMutex); | 245 MutexLocker lock(m_threadCreationMutex); |
248 | 246 |
247 if (m_terminated) // The worker was terminated before the thread had a c hance to run. | |
248 return; | |
249 | |
250 m_microtaskRunner = adoptPtr(new MicrotaskRunner); | |
251 m_thread->addTaskObserver(m_microtaskRunner.get()); | |
249 m_pendingGCRunner = adoptPtr(new PendingGCRunner); | 252 m_pendingGCRunner = adoptPtr(new PendingGCRunner); |
250 m_messageLoopInterruptor = adoptPtr(new MessageLoopInterruptor(m_thread. get())); | 253 m_messageLoopInterruptor = adoptPtr(new MessageLoopInterruptor(m_thread. get())); |
251 m_thread->addTaskObserver(m_pendingGCRunner.get()); | 254 m_thread->addTaskObserver(m_pendingGCRunner.get()); |
252 ThreadState::attach(); | 255 ThreadState::attach(); |
253 ThreadState::current()->addInterruptor(m_messageLoopInterruptor.get()); | 256 ThreadState::current()->addInterruptor(m_messageLoopInterruptor.get()); |
254 m_workerGlobalScope = createWorkerGlobalScope(m_startupData.release()); | 257 m_workerGlobalScope = createWorkerGlobalScope(m_startupData.release()); |
255 | 258 |
256 m_sharedTimer = adoptPtr(new WorkerSharedTimer(this)); | 259 m_sharedTimer = adoptPtr(new WorkerSharedTimer(this)); |
257 PlatformThreadData::current().threadTimers().setSharedTimer(m_sharedTime r.get()); | 260 PlatformThreadData::current().threadTimers().setSharedTimer(m_sharedTime r.get()); |
258 | |
259 if (m_terminated) { | |
260 // The worker was terminated before the thread had a chance to run. Since the context didn't exist yet, | |
261 // forbidExecution() couldn't be called from stop(). | |
262 m_workerGlobalScope->script()->forbidExecution(); | |
263 } | |
264 } | 261 } |
265 | 262 |
266 // The corresponding call to didStopWorkerRunLoop is in | 263 // The corresponding call to didStopWorkerRunLoop is in |
267 // ~WorkerScriptController. | 264 // ~WorkerScriptController. |
268 blink::Platform::current()->didStartWorkerRunLoop(blink::WebWorkerRunLoop(th is)); | 265 blink::Platform::current()->didStartWorkerRunLoop(blink::WebWorkerRunLoop(th is)); |
269 | 266 |
270 // Notify proxy that a new WorkerGlobalScope has been created and started. | 267 // Notify proxy that a new WorkerGlobalScope has been created and started. |
271 m_workerReportingProxy.workerGlobalScopeStarted(m_workerGlobalScope.get()); | 268 m_workerReportingProxy.workerGlobalScopeStarted(m_workerGlobalScope.get()); |
272 | 269 |
273 WorkerScriptController* script = m_workerGlobalScope->script(); | 270 WorkerScriptController* script = m_workerGlobalScope->script(); |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
371 { | 368 { |
372 // Prevent the deadlock between GC and an attempt to stop a thread. | 369 // Prevent the deadlock between GC and an attempt to stop a thread. |
373 ThreadState::SafePointScope safePointScope(ThreadState::HeapPointersOnStack) ; | 370 ThreadState::SafePointScope safePointScope(ThreadState::HeapPointersOnStack) ; |
374 | 371 |
375 // Protect against this method and initialize() racing each other. | 372 // Protect against this method and initialize() racing each other. |
376 MutexLocker lock(m_threadCreationMutex); | 373 MutexLocker lock(m_threadCreationMutex); |
377 | 374 |
378 // If stop has already been called, just return. | 375 // If stop has already been called, just return. |
379 if (m_terminated) | 376 if (m_terminated) |
380 return; | 377 return; |
378 m_terminated = true; | |
381 | 379 |
382 // Signal the thread to notify that the thread's stopping. | 380 // Signal the thread to notify that the thread's stopping. |
383 if (m_shutdownEvent) | 381 if (m_shutdownEvent) |
384 m_shutdownEvent->signal(); | 382 m_shutdownEvent->signal(); |
385 | 383 |
386 if (!m_workerGlobalScope) | 384 if (!m_workerGlobalScope) |
387 return; | 385 return; |
388 | 386 |
389 // Ensure that tasks are being handled by thread event loop. If script execu tion weren't forbidden, a while(1) loop in JS could keep the thread alive foreve r. | 387 // Ensure that tasks are being handled by thread event loop. If script execu tion weren't forbidden, a while(1) loop in JS could keep the thread alive foreve r. |
390 m_workerGlobalScope->script()->scheduleExecutionTermination(); | 388 m_workerGlobalScope->script()->scheduleExecutionTermination(); |
391 m_workerGlobalScope->wasRequestedToTerminate(); | 389 m_workerGlobalScope->wasRequestedToTerminate(); |
392 InspectorInstrumentation::didKillAllExecutionContextTasks(m_workerGlobalScop e.get()); | 390 InspectorInstrumentation::didKillAllExecutionContextTasks(m_workerGlobalScop e.get()); |
393 m_debuggerMessageQueue.kill(); | 391 m_debuggerMessageQueue.kill(); |
394 postTask(WorkerThreadShutdownStartTask::create()); | 392 postTask(WorkerThreadShutdownStartTask::create()); |
395 m_terminated = true; | |
396 } | 393 } |
397 | 394 |
398 bool WorkerThread::isCurrentThread() const | 395 bool WorkerThread::isCurrentThread() const |
399 { | 396 { |
400 return m_thread && m_thread->isCurrentThread(); | 397 return m_thread && m_thread->isCurrentThread(); |
401 } | 398 } |
402 | 399 |
403 void WorkerThread::idleHandler() | 400 void WorkerThread::idleHandler() |
404 { | 401 { |
405 ASSERT(m_workerGlobalScope.get()); | 402 ASSERT(m_workerGlobalScope.get()); |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
464 InspectorInstrumentation::didLeaveNestedRunLoop(m_workerGlobalScope.get()); | 461 InspectorInstrumentation::didLeaveNestedRunLoop(m_workerGlobalScope.get()); |
465 } | 462 } |
466 | 463 |
467 void WorkerThread::setWorkerInspectorController(WorkerInspectorController* worke rInspectorController) | 464 void WorkerThread::setWorkerInspectorController(WorkerInspectorController* worke rInspectorController) |
468 { | 465 { |
469 MutexLocker locker(m_workerInspectorControllerMutex); | 466 MutexLocker locker(m_workerInspectorControllerMutex); |
470 m_workerInspectorController = workerInspectorController; | 467 m_workerInspectorController = workerInspectorController; |
471 } | 468 } |
472 | 469 |
473 } // namespace blink | 470 } // namespace blink |
OLD | NEW |