| 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 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 MutexLocker lock(threadSetMutex()); | 217 MutexLocker lock(threadSetMutex()); |
| 218 ASSERT(workerThreads().contains(this)); | 218 ASSERT(workerThreads().contains(this)); |
| 219 workerThreads().remove(this); | 219 workerThreads().remove(this); |
| 220 } | 220 } |
| 221 | 221 |
| 222 void WorkerThread::start() | 222 void WorkerThread::start() |
| 223 { | 223 { |
| 224 if (m_thread) | 224 if (m_thread) |
| 225 return; | 225 return; |
| 226 | 226 |
| 227 m_thread = adoptPtr(blink::Platform::current()->createThread("WebCore: Worke
r")); | 227 m_thread = WebThreadSupportingGC::create("WebCore: Worker"); |
| 228 m_thread->postTask(new Task(WTF::bind(&WorkerThread::initialize, this))); | 228 m_thread->postTask(new Task(WTF::bind(&WorkerThread::initialize, this))); |
| 229 } | 229 } |
| 230 | 230 |
| 231 void WorkerThread::interruptAndDispatchInspectorCommands() | 231 void WorkerThread::interruptAndDispatchInspectorCommands() |
| 232 { | 232 { |
| 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 | 243 |
| 244 { | 244 { |
| 245 MutexLocker lock(m_threadCreationMutex); | 245 MutexLocker lock(m_threadCreationMutex); |
| 246 | 246 |
| 247 // The worker was terminated before the thread had a chance to run. | 247 // The worker was terminated before the thread had a chance to run. |
| 248 if (m_terminated) { | 248 if (m_terminated) { |
| 249 // Notify the proxy that the WorkerGlobalScope has been disposed of. | 249 // Notify the proxy that the WorkerGlobalScope has been disposed of. |
| 250 // This can free this thread object, hence it must not be touched af
terwards. | 250 // This can free this thread object, hence it must not be touched af
terwards. |
| 251 m_workerReportingProxy.workerGlobalScopeDestroyed(); | 251 m_workerReportingProxy.workerGlobalScopeDestroyed(); |
| 252 return; | 252 return; |
| 253 } | 253 } |
| 254 | 254 |
| 255 m_microtaskRunner = adoptPtr(new MicrotaskRunner); | 255 m_microtaskRunner = adoptPtr(new MicrotaskRunner); |
| 256 m_thread->addTaskObserver(m_microtaskRunner.get()); | 256 m_thread->addTaskObserver(m_microtaskRunner.get()); |
| 257 m_pendingGCRunner = adoptPtr(new PendingGCRunner); | 257 m_thread->attachGC(); |
| 258 m_messageLoopInterruptor = adoptPtr(new MessageLoopInterruptor(m_thread.
get())); | |
| 259 m_thread->addTaskObserver(m_pendingGCRunner.get()); | |
| 260 ThreadState::attach(); | |
| 261 ThreadState::current()->addInterruptor(m_messageLoopInterruptor.get()); | |
| 262 m_workerGlobalScope = createWorkerGlobalScope(m_startupData.release()); | 258 m_workerGlobalScope = createWorkerGlobalScope(m_startupData.release()); |
| 263 | 259 |
| 264 m_sharedTimer = adoptPtr(new WorkerSharedTimer(this)); | 260 m_sharedTimer = adoptPtr(new WorkerSharedTimer(this)); |
| 265 PlatformThreadData::current().threadTimers().setSharedTimer(m_sharedTime
r.get()); | 261 PlatformThreadData::current().threadTimers().setSharedTimer(m_sharedTime
r.get()); |
| 266 } | 262 } |
| 267 | 263 |
| 268 // The corresponding call to didStopWorkerRunLoop is in | 264 // The corresponding call to didStopWorkerRunLoop is in |
| 269 // ~WorkerScriptController. | 265 // ~WorkerScriptController. |
| 270 blink::Platform::current()->didStartWorkerRunLoop(blink::WebWorkerRunLoop(th
is)); | 266 blink::Platform::current()->didStartWorkerRunLoop(blink::WebWorkerRunLoop(th
is)); |
| 271 | 267 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 291 | 287 |
| 292 // The below assignment will destroy the context, which will in turn notify
messaging proxy. | 288 // The below assignment will destroy the context, which will in turn notify
messaging proxy. |
| 293 // We cannot let any objects survive past thread exit, because no other thre
ad will run GC or otherwise destroy them. | 289 // We cannot let any objects survive past thread exit, because no other thre
ad will run GC or otherwise destroy them. |
| 294 // If Oilpan is enabled, we detach of the context/global scope, with the fin
al heap cleanup below sweeping it out. | 290 // If Oilpan is enabled, we detach of the context/global scope, with the fin
al heap cleanup below sweeping it out. |
| 295 #if !ENABLE(OILPAN) | 291 #if !ENABLE(OILPAN) |
| 296 ASSERT(m_workerGlobalScope->hasOneRef()); | 292 ASSERT(m_workerGlobalScope->hasOneRef()); |
| 297 #endif | 293 #endif |
| 298 m_workerGlobalScope->dispose(); | 294 m_workerGlobalScope->dispose(); |
| 299 m_workerGlobalScope = nullptr; | 295 m_workerGlobalScope = nullptr; |
| 300 | 296 |
| 301 ThreadState::current()->removeInterruptor(m_messageLoopInterruptor.get()); | 297 m_thread->detachGC(); |
| 302 | |
| 303 // Detach the ThreadState, cleaning out the thread's heap by | |
| 304 // performing a final GC. The cleanup operation will at the end | |
| 305 // assert that the heap is empty. If the heap does not become | |
| 306 // empty, there are still pointers into the heap and those | |
| 307 // pointers will be dangling after thread termination because we | |
| 308 // are destroying the heap. It is important to detach while the | |
| 309 // thread is still valid. In particular, finalizers for objects in | |
| 310 // the heap for this thread will need to access thread local data. | |
| 311 ThreadState::detach(); | |
| 312 | 298 |
| 313 m_thread->removeTaskObserver(m_microtaskRunner.get()); | 299 m_thread->removeTaskObserver(m_microtaskRunner.get()); |
| 314 m_microtaskRunner = nullptr; | 300 m_microtaskRunner = nullptr; |
| 315 m_thread->removeTaskObserver(m_pendingGCRunner.get()); | |
| 316 m_pendingGCRunner = nullptr; | |
| 317 m_messageLoopInterruptor = nullptr; | |
| 318 | 301 |
| 319 // Notify the proxy that the WorkerGlobalScope has been disposed of. | 302 // Notify the proxy that the WorkerGlobalScope has been disposed of. |
| 320 // This can free this thread object, hence it must not be touched afterwards
. | 303 // This can free this thread object, hence it must not be touched afterwards
. |
| 321 workerReportingProxy().workerGlobalScopeDestroyed(); | 304 workerReportingProxy().workerGlobalScopeDestroyed(); |
| 322 | 305 |
| 323 // Clean up PlatformThreadData before WTF::WTFThreadData goes away! | 306 // Clean up PlatformThreadData before WTF::WTFThreadData goes away! |
| 324 PlatformThreadData::current().destroy(); | 307 PlatformThreadData::current().destroy(); |
| 325 } | 308 } |
| 326 | 309 |
| 327 class WorkerThreadShutdownFinishTask : public ExecutionContextTask { | 310 class WorkerThreadShutdownFinishTask : public ExecutionContextTask { |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 466 InspectorInstrumentation::didLeaveNestedRunLoop(m_workerGlobalScope.get()); | 449 InspectorInstrumentation::didLeaveNestedRunLoop(m_workerGlobalScope.get()); |
| 467 } | 450 } |
| 468 | 451 |
| 469 void WorkerThread::setWorkerInspectorController(WorkerInspectorController* worke
rInspectorController) | 452 void WorkerThread::setWorkerInspectorController(WorkerInspectorController* worke
rInspectorController) |
| 470 { | 453 { |
| 471 MutexLocker locker(m_workerInspectorControllerMutex); | 454 MutexLocker locker(m_workerInspectorControllerMutex); |
| 472 m_workerInspectorController = workerInspectorController; | 455 m_workerInspectorController = workerInspectorController; |
| 473 } | 456 } |
| 474 | 457 |
| 475 } // namespace blink | 458 } // namespace blink |
| OLD | NEW |