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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 #include "platform/heap/ThreadState.h" | 44 #include "platform/heap/ThreadState.h" |
45 #include "platform/weborigin/KURL.h" | 45 #include "platform/weborigin/KURL.h" |
46 #include "public/platform/WebThread.h" | 46 #include "public/platform/WebThread.h" |
47 #include "wtf/Functional.h" | 47 #include "wtf/Functional.h" |
48 #include "wtf/Noncopyable.h" | 48 #include "wtf/Noncopyable.h" |
49 #include "wtf/text/WTFString.h" | 49 #include "wtf/text/WTFString.h" |
50 #include <limits.h> | 50 #include <limits.h> |
51 | 51 |
52 namespace blink { | 52 namespace blink { |
53 | 53 |
54 class WorkerMicrotaskRunner : public WebThread::TaskObserver { | 54 class WorkerThread::WorkerMicrotaskRunner : public WebThread::TaskObserver { |
55 public: | 55 public: |
56 explicit WorkerMicrotaskRunner(WorkerThread* workerThread) | 56 explicit WorkerMicrotaskRunner(WorkerThread* workerThread) |
57 : m_workerThread(workerThread) | 57 : m_workerThread(workerThread) |
58 { | 58 { |
59 } | 59 } |
60 | 60 |
61 void willProcessTask() override | 61 void willProcessTask() override |
62 { | 62 { |
63 // No tasks should get executed after we have closed. | 63 // No tasks should get executed after we have closed. |
64 DCHECK(!m_workerThread->workerGlobalScope() || !m_workerThread->workerGl
obalScope()->isClosing()); | 64 DCHECK(!m_workerThread->workerGlobalScope() || !m_workerThread->workerGl
obalScope()->isClosing()); |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
231 } | 231 } |
232 | 232 |
233 CachedMetadataHandler* handler = workerGlobalScope()->createWorkerScriptCach
edMetadataHandler(scriptURL, cachedMetaData.get()); | 233 CachedMetadataHandler* handler = workerGlobalScope()->createWorkerScriptCach
edMetadataHandler(scriptURL, cachedMetaData.get()); |
234 bool success = m_workerGlobalScope->scriptController()->evaluate(ScriptSourc
eCode(sourceCode, scriptURL), nullptr, handler, v8CacheOptions); | 234 bool success = m_workerGlobalScope->scriptController()->evaluate(ScriptSourc
eCode(sourceCode, scriptURL), nullptr, handler, v8CacheOptions); |
235 m_workerGlobalScope->didEvaluateWorkerScript(); | 235 m_workerGlobalScope->didEvaluateWorkerScript(); |
236 m_workerReportingProxy.didEvaluateWorkerScript(success); | 236 m_workerReportingProxy.didEvaluateWorkerScript(success); |
237 | 237 |
238 postInitialize(); | 238 postInitialize(); |
239 } | 239 } |
240 | 240 |
241 void WorkerThread::performShutdownTask() | 241 void WorkerThread::prepareForShutdown() |
| 242 { |
| 243 DCHECK(isCurrentThread()); |
| 244 { |
| 245 MutexLocker lock(m_threadStateMutex); |
| 246 if (m_readyToShutdown) |
| 247 return; |
| 248 m_readyToShutdown = true; |
| 249 } |
| 250 |
| 251 workerReportingProxy().willDestroyWorkerGlobalScope(); |
| 252 InspectorInstrumentation::allAsyncTasksCanceled(workerGlobalScope()); |
| 253 workerGlobalScope()->dispose(); |
| 254 workerBackingThread().backingThread().removeTaskObserver(m_microtaskRunner.g
et()); |
| 255 } |
| 256 |
| 257 void WorkerThread::performShutdown() |
242 { | 258 { |
243 DCHECK(isCurrentThread()); | 259 DCHECK(isCurrentThread()); |
244 #if DCHECK_IS_ON | 260 #if DCHECK_IS_ON |
245 { | 261 { |
246 MutexLocker lock(m_threadStateMutex); | 262 MutexLocker lock(m_threadStateMutex); |
247 DCHECK(m_terminated); | 263 DCHECK(m_terminated); |
248 DCHECK(m_readyToShutdown); | 264 DCHECK(m_readyToShutdown); |
249 } | 265 } |
250 #endif | 266 #endif |
251 | 267 |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
322 } else { | 338 } else { |
323 // TODO(yhirano): TerminateExecution should be called more | 339 // TODO(yhirano): TerminateExecution should be called more |
324 // carefully (https://crbug.com/413518). | 340 // carefully (https://crbug.com/413518). |
325 isolate()->TerminateExecution(); | 341 isolate()->TerminateExecution(); |
326 } | 342 } |
327 } | 343 } |
328 } | 344 } |
329 | 345 |
330 m_inspectorTaskRunner->kill(); | 346 m_inspectorTaskRunner->kill(); |
331 workerBackingThread().backingThread().postTask(BLINK_FROM_HERE, threadSafeBi
nd(&WorkerThread::prepareForShutdown, AllowCrossThreadAccess(this))); | 347 workerBackingThread().backingThread().postTask(BLINK_FROM_HERE, threadSafeBi
nd(&WorkerThread::prepareForShutdown, AllowCrossThreadAccess(this))); |
332 workerBackingThread().backingThread().postTask(BLINK_FROM_HERE, threadSafeBi
nd(&WorkerThread::performShutdownTask, AllowCrossThreadAccess(this))); | 348 workerBackingThread().backingThread().postTask(BLINK_FROM_HERE, threadSafeBi
nd(&WorkerThread::performShutdown, AllowCrossThreadAccess(this))); |
333 } | 349 } |
334 | 350 |
335 void WorkerThread::terminateAndWait() | 351 void WorkerThread::terminateAndWait() |
336 { | 352 { |
337 DCHECK(isMainThread()); | 353 DCHECK(isMainThread()); |
338 terminate(); | 354 terminate(); |
339 m_shutdownEvent->wait(); | 355 m_shutdownEvent->wait(); |
340 } | 356 } |
341 | 357 |
342 void WorkerThread::terminateAndWaitForAllWorkers() | 358 void WorkerThread::terminateAndWaitForAllWorkers() |
343 { | 359 { |
344 DCHECK(isMainThread()); | 360 DCHECK(isMainThread()); |
345 | 361 |
346 // Keep this lock to prevent WorkerThread instances from being destroyed. | 362 // Keep this lock to prevent WorkerThread instances from being destroyed. |
347 MutexLocker lock(threadSetMutex()); | 363 MutexLocker lock(threadSetMutex()); |
348 HashSet<WorkerThread*> threads = workerThreads(); | 364 HashSet<WorkerThread*> threads = workerThreads(); |
349 for (WorkerThread* thread : threads) | 365 for (WorkerThread* thread : threads) |
350 thread->terminate(); | 366 thread->terminate(); |
351 | 367 |
352 for (WorkerThread* thread : threads) | 368 for (WorkerThread* thread : threads) |
353 thread->m_shutdownEvent->wait(); | 369 thread->m_shutdownEvent->wait(); |
354 } | 370 } |
355 | 371 |
356 void WorkerThread::prepareForShutdown() | |
357 { | |
358 DCHECK(isCurrentThread()); | |
359 { | |
360 MutexLocker lock(m_threadStateMutex); | |
361 if (m_readyToShutdown) | |
362 return; | |
363 m_readyToShutdown = true; | |
364 } | |
365 | |
366 workerReportingProxy().willDestroyWorkerGlobalScope(); | |
367 InspectorInstrumentation::allAsyncTasksCanceled(workerGlobalScope()); | |
368 workerGlobalScope()->dispose(); | |
369 workerBackingThread().backingThread().removeTaskObserver(m_microtaskRunner.g
et()); | |
370 } | |
371 | |
372 WorkerGlobalScope* WorkerThread::workerGlobalScope() | 372 WorkerGlobalScope* WorkerThread::workerGlobalScope() |
373 { | 373 { |
374 DCHECK(isCurrentThread()); | 374 DCHECK(isCurrentThread()); |
375 return m_workerGlobalScope.get(); | 375 return m_workerGlobalScope.get(); |
376 } | 376 } |
377 | 377 |
378 bool WorkerThread::terminated() | 378 bool WorkerThread::terminated() |
379 { | 379 { |
380 MutexLocker lock(m_threadStateMutex); | 380 MutexLocker lock(m_threadStateMutex); |
381 return m_terminated; | 381 return m_terminated; |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
457 } while (task && m_pausedInDebugger); | 457 } while (task && m_pausedInDebugger); |
458 ThreadDebugger::idleFinished(isolate()); | 458 ThreadDebugger::idleFinished(isolate()); |
459 } | 459 } |
460 | 460 |
461 void WorkerThread::stopRunningDebuggerTasksOnPause() | 461 void WorkerThread::stopRunningDebuggerTasksOnPause() |
462 { | 462 { |
463 m_pausedInDebugger = false; | 463 m_pausedInDebugger = false; |
464 } | 464 } |
465 | 465 |
466 } // namespace blink | 466 } // namespace blink |
OLD | NEW |