| 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 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 m_microtaskRunner = adoptPtr(new WorkerMicrotaskRunner(this)); | 220 m_microtaskRunner = adoptPtr(new WorkerMicrotaskRunner(this)); |
| 221 backingThread().addTaskObserver(m_microtaskRunner.get()); | 221 backingThread().addTaskObserver(m_microtaskRunner.get()); |
| 222 backingThread().initialize(); | 222 backingThread().initialize(); |
| 223 | 223 |
| 224 m_isolate = initializeIsolate(); | 224 m_isolate = initializeIsolate(); |
| 225 m_workerGlobalScope = createWorkerGlobalScope(startupData); | 225 m_workerGlobalScope = createWorkerGlobalScope(startupData); |
| 226 m_workerGlobalScope->scriptLoaded(sourceCode.length(), cachedMetaData.ge
t() ? cachedMetaData->size() : 0); | 226 m_workerGlobalScope->scriptLoaded(sourceCode.length(), cachedMetaData.ge
t() ? cachedMetaData->size() : 0); |
| 227 } | 227 } |
| 228 m_webScheduler = backingThread().platformThread().scheduler(); | 228 m_webScheduler = backingThread().platformThread().scheduler(); |
| 229 | 229 |
| 230 // The corresponding call to stopRunLoop() is in ~WorkerScriptController(). | 230 // The corresponding call to didStopRunLoop() is in ~WorkerScriptController(
). |
| 231 didStartRunLoop(); | 231 didStartRunLoop(); |
| 232 | 232 |
| 233 // Notify proxy that a new WorkerGlobalScope has been created and started. | 233 // Notify proxy that a new WorkerGlobalScope has been created and started. |
| 234 m_workerReportingProxy.workerGlobalScopeStarted(m_workerGlobalScope.get()); | 234 m_workerReportingProxy.workerGlobalScopeStarted(m_workerGlobalScope.get()); |
| 235 | 235 |
| 236 WorkerScriptController* script = m_workerGlobalScope->script(); | 236 WorkerScriptController* script = m_workerGlobalScope->script(); |
| 237 if (!script->isExecutionForbidden()) | 237 if (!script->isExecutionForbidden()) |
| 238 script->initializeContextIfNeeded(); | 238 script->initializeContextIfNeeded(); |
| 239 m_workerGlobalScope->workerInspectorController()->workerContextInitialized(s
tartMode == PauseWorkerGlobalScopeOnStart); | 239 m_workerGlobalScope->workerInspectorController()->workerContextInitialized(s
tartMode == PauseWorkerGlobalScopeOnStart); |
| 240 | 240 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 278 | 278 |
| 279 m_microtaskRunner = nullptr; | 279 m_microtaskRunner = nullptr; |
| 280 | 280 |
| 281 // Notify the proxy that the WorkerGlobalScope has been disposed of. | 281 // Notify the proxy that the WorkerGlobalScope has been disposed of. |
| 282 // This can free this thread object, hence it must not be touched afterwards
. | 282 // This can free this thread object, hence it must not be touched afterwards
. |
| 283 workerReportingProxy().workerThreadTerminated(); | 283 workerReportingProxy().workerThreadTerminated(); |
| 284 | 284 |
| 285 m_terminationEvent->signal(); | 285 m_terminationEvent->signal(); |
| 286 } | 286 } |
| 287 | 287 |
| 288 | 288 void WorkerThread::terminate() |
| 289 void WorkerThread::stop() | |
| 290 { | 289 { |
| 291 // Prevent the deadlock between GC and an attempt to stop a thread. | 290 // Prevent the deadlock between GC and an attempt to terminate a thread. |
| 292 SafePointScope safePointScope(ThreadState::HeapPointersOnStack); | 291 SafePointScope safePointScope(ThreadState::HeapPointersOnStack); |
| 293 stopInternal(); | 292 terminateInternal(); |
| 294 } | 293 } |
| 295 | 294 |
| 296 void WorkerThread::terminateAndWait() | 295 void WorkerThread::terminateAndWait() |
| 297 { | 296 { |
| 298 stop(); | 297 terminate(); |
| 299 m_terminationEvent->wait(); | 298 m_terminationEvent->wait(); |
| 300 } | 299 } |
| 301 | 300 |
| 302 bool WorkerThread::terminated() | 301 bool WorkerThread::terminated() |
| 303 { | 302 { |
| 304 MutexLocker lock(m_threadStateMutex); | 303 MutexLocker lock(m_threadStateMutex); |
| 305 return m_terminated; | 304 return m_terminated; |
| 306 } | 305 } |
| 307 | 306 |
| 308 void WorkerThread::stopInternal() | 307 void WorkerThread::terminateInternal() |
| 309 { | 308 { |
| 310 // Protect against this method, initialize() or termination via the global s
cope racing each other. | 309 // Protect against this method, initialize() or termination via the global s
cope racing each other. |
| 311 MutexLocker lock(m_threadStateMutex); | 310 MutexLocker lock(m_threadStateMutex); |
| 312 | 311 |
| 313 // If stop has already been called, just return. | 312 // If terminateInternal has already been called, just return. |
| 314 if (m_terminated) | 313 if (m_terminated) |
| 315 return; | 314 return; |
| 316 m_terminated = true; | 315 m_terminated = true; |
| 317 | 316 |
| 318 // Signal the thread to notify that the thread's stopping. | 317 // Signal the thread to notify that the thread's stopping. |
| 319 if (m_shutdownEvent) | 318 if (m_shutdownEvent) |
| 320 m_shutdownEvent->signal(); | 319 m_shutdownEvent->signal(); |
| 321 | 320 |
| 322 // If the thread has already initiated shut down, just return. | 321 // If the thread has already initiated shut down, just return. |
| 323 if (m_shutdown) | 322 if (m_shutdown) |
| (...skipping 24 matching lines...) Expand all Loading... |
| 348 ASSERT(isCurrentThread()); | 347 ASSERT(isCurrentThread()); |
| 349 Platform::current()->didStopWorkerRunLoop(); | 348 Platform::current()->didStopWorkerRunLoop(); |
| 350 } | 349 } |
| 351 | 350 |
| 352 void WorkerThread::terminateAndWaitForAllWorkers() | 351 void WorkerThread::terminateAndWaitForAllWorkers() |
| 353 { | 352 { |
| 354 // Keep this lock to prevent WorkerThread instances from being destroyed. | 353 // Keep this lock to prevent WorkerThread instances from being destroyed. |
| 355 MutexLocker lock(threadSetMutex()); | 354 MutexLocker lock(threadSetMutex()); |
| 356 HashSet<WorkerThread*> threads = workerThreads(); | 355 HashSet<WorkerThread*> threads = workerThreads(); |
| 357 for (WorkerThread* thread : threads) | 356 for (WorkerThread* thread : threads) |
| 358 thread->stopInternal(); | 357 thread->terminateInternal(); |
| 359 | 358 |
| 360 for (WorkerThread* thread : threads) | 359 for (WorkerThread* thread : threads) |
| 361 thread->terminationEvent()->wait(); | 360 thread->m_terminationEvent->wait(); |
| 362 } | 361 } |
| 363 | 362 |
| 364 bool WorkerThread::isCurrentThread() | 363 bool WorkerThread::isCurrentThread() |
| 365 { | 364 { |
| 366 return m_started && backingThread().isCurrentThread(); | 365 return m_started && backingThread().isCurrentThread(); |
| 367 } | 366 } |
| 368 | 367 |
| 369 void WorkerThread::performIdleWork(double deadlineSeconds) | 368 void WorkerThread::performIdleWork(double deadlineSeconds) |
| 370 { | 369 { |
| 371 double gcDeadlineSeconds = deadlineSeconds; | 370 double gcDeadlineSeconds = deadlineSeconds; |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 472 InspectorInstrumentation::didLeaveNestedRunLoop(m_workerGlobalScope.get()); | 471 InspectorInstrumentation::didLeaveNestedRunLoop(m_workerGlobalScope.get()); |
| 473 } | 472 } |
| 474 | 473 |
| 475 void WorkerThread::setWorkerInspectorController(WorkerInspectorController* worke
rInspectorController) | 474 void WorkerThread::setWorkerInspectorController(WorkerInspectorController* worke
rInspectorController) |
| 476 { | 475 { |
| 477 MutexLocker locker(m_workerInspectorControllerMutex); | 476 MutexLocker locker(m_workerInspectorControllerMutex); |
| 478 m_workerInspectorController = workerInspectorController; | 477 m_workerInspectorController = workerInspectorController; |
| 479 } | 478 } |
| 480 | 479 |
| 481 } // namespace blink | 480 } // namespace blink |
| OLD | NEW |