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 12 matching lines...) Expand all Loading... |
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
24 * | 24 * |
25 */ | 25 */ |
26 | 26 |
27 #ifndef WorkerThread_h | 27 #ifndef WorkerThread_h |
28 #define WorkerThread_h | 28 #define WorkerThread_h |
29 | 29 |
30 #include <memory> | 30 #include <memory> |
31 | 31 |
32 #include "core/CoreExport.h" | 32 #include "core/CoreExport.h" |
| 33 #include "core/dom/TaskRunnerHelper.h" |
33 #include "core/frame/csp/ContentSecurityPolicy.h" | 34 #include "core/frame/csp/ContentSecurityPolicy.h" |
34 #include "core/workers/ParentFrameTaskRunners.h" | |
35 #include "core/workers/WorkerLoaderProxy.h" | 35 #include "core/workers/WorkerLoaderProxy.h" |
36 #include "core/workers/WorkerThreadLifecycleObserver.h" | 36 #include "core/workers/WorkerThreadLifecycleObserver.h" |
37 #include "platform/LifecycleNotifier.h" | 37 #include "platform/LifecycleNotifier.h" |
38 #include "platform/WaitableEvent.h" | 38 #include "platform/WaitableEvent.h" |
39 #include "platform/WebTaskRunner.h" | 39 #include "platform/WebTaskRunner.h" |
40 #include "public/platform/WebThread.h" | 40 #include "public/platform/WebThread.h" |
41 #include "v8/include/v8.h" | 41 #include "v8/include/v8.h" |
42 #include "wtf/Forward.h" | 42 #include "wtf/Forward.h" |
43 #include "wtf/Functional.h" | 43 #include "wtf/Functional.h" |
44 #include "wtf/PassRefPtr.h" | 44 #include "wtf/PassRefPtr.h" |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 NotTerminated, | 100 NotTerminated, |
101 GracefullyTerminated, | 101 GracefullyTerminated, |
102 SyncForciblyTerminated, | 102 SyncForciblyTerminated, |
103 AsyncForciblyTerminated, | 103 AsyncForciblyTerminated, |
104 LastEnum, | 104 LastEnum, |
105 }; | 105 }; |
106 | 106 |
107 virtual ~WorkerThread(); | 107 virtual ~WorkerThread(); |
108 | 108 |
109 // Called on the main thread. | 109 // Called on the main thread. |
110 void start(std::unique_ptr<WorkerThreadStartupData>, ParentFrameTaskRunners*); | 110 void start(std::unique_ptr<WorkerThreadStartupData>, FrameTaskRunnersHolder*); |
111 void terminate(); | 111 void terminate(); |
112 | 112 |
113 // Called on the main thread. Internally calls terminateInternal() and wait | 113 // Called on the main thread. Internally calls terminateInternal() and wait |
114 // (by *blocking* the calling thread) until the worker(s) is/are shut down. | 114 // (by *blocking* the calling thread) until the worker(s) is/are shut down. |
115 void terminateAndWait(); | 115 void terminateAndWait(); |
116 static void terminateAndWaitForAllWorkers(); | 116 static void terminateAndWaitForAllWorkers(); |
117 | 117 |
118 // WebThread::TaskObserver. | 118 // WebThread::TaskObserver. |
119 void willProcessTask() override; | 119 void willProcessTask() override; |
120 void didProcessTask() override; | 120 void didProcessTask() override; |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 static HashSet<WorkerThread*>& workerThreads(); | 164 static HashSet<WorkerThread*>& workerThreads(); |
165 | 165 |
166 int getWorkerThreadId() const { return m_workerThreadId; } | 166 int getWorkerThreadId() const { return m_workerThreadId; } |
167 | 167 |
168 PlatformThreadId platformThreadId(); | 168 PlatformThreadId platformThreadId(); |
169 | 169 |
170 bool isForciblyTerminated(); | 170 bool isForciblyTerminated(); |
171 | 171 |
172 void waitForShutdownForTesting() { m_shutdownEvent->wait(); } | 172 void waitForShutdownForTesting() { m_shutdownEvent->wait(); } |
173 | 173 |
174 ParentFrameTaskRunners* getParentFrameTaskRunners() const { | |
175 return m_parentFrameTaskRunners.get(); | |
176 } | |
177 | |
178 protected: | 174 protected: |
179 WorkerThread(PassRefPtr<WorkerLoaderProxy>, WorkerReportingProxy&); | 175 WorkerThread(PassRefPtr<WorkerLoaderProxy>, WorkerReportingProxy&); |
180 | 176 |
181 // Factory method for creating a new worker context for the thread. | 177 // Factory method for creating a new worker context for the thread. |
182 // Called on the worker thread. | 178 // Called on the worker thread. |
183 virtual WorkerOrWorkletGlobalScope* createWorkerGlobalScope( | 179 virtual WorkerOrWorkletGlobalScope* createWorkerGlobalScope( |
184 std::unique_ptr<WorkerThreadStartupData>) = 0; | 180 std::unique_ptr<WorkerThreadStartupData>) = 0; |
185 | 181 |
186 // Returns true when this WorkerThread owns the associated | 182 // Returns true when this WorkerThread owns the associated |
187 // WorkerBackingThread exclusively. If this function returns true, the | 183 // WorkerBackingThread exclusively. If this function returns true, the |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 // Forcibly terminates the worker execution. This must be called with | 237 // Forcibly terminates the worker execution. This must be called with |
242 // |m_threadStateMutex| acquired. | 238 // |m_threadStateMutex| acquired. |
243 void forciblyTerminateExecution(const MutexLocker&, ExitCode); | 239 void forciblyTerminateExecution(const MutexLocker&, ExitCode); |
244 | 240 |
245 // Returns true if termination or shutdown sequence has started. This is | 241 // Returns true if termination or shutdown sequence has started. This is |
246 // thread safe. | 242 // thread safe. |
247 // Note that this returns false when the sequence has already started but it | 243 // Note that this returns false when the sequence has already started but it |
248 // hasn't been notified to the calling thread. | 244 // hasn't been notified to the calling thread. |
249 bool isInShutdown(); | 245 bool isInShutdown(); |
250 | 246 |
251 void initializeOnWorkerThread(std::unique_ptr<WorkerThreadStartupData>); | 247 void initializeOnWorkerThread(std::unique_ptr<WorkerThreadStartupData>, |
| 248 FrameTaskRunnersHolder*); |
252 void prepareForShutdownOnWorkerThread(); | 249 void prepareForShutdownOnWorkerThread(); |
253 void performShutdownOnWorkerThread(); | 250 void performShutdownOnWorkerThread(); |
254 void performTaskOnWorkerThread(std::unique_ptr<CrossThreadClosure>); | 251 void performTaskOnWorkerThread(std::unique_ptr<CrossThreadClosure>); |
255 void performDebuggerTaskOnWorkerThread(std::unique_ptr<CrossThreadClosure>); | 252 void performDebuggerTaskOnWorkerThread(std::unique_ptr<CrossThreadClosure>); |
256 void performDebuggerTaskDontWaitOnWorkerThread(); | 253 void performDebuggerTaskDontWaitOnWorkerThread(); |
257 | 254 |
258 // These must be called with |m_threadStateMutex| acquired. | 255 // These must be called with |m_threadStateMutex| acquired. |
259 void setThreadState(const MutexLocker&, ThreadState); | 256 void setThreadState(const MutexLocker&, ThreadState); |
260 void setExitCode(const MutexLocker&, ExitCode); | 257 void setExitCode(const MutexLocker&, ExitCode); |
261 bool isThreadStateMutexLocked(const MutexLocker&); | 258 bool isThreadStateMutexLocked(const MutexLocker&); |
(...skipping 22 matching lines...) Expand all Loading... |
284 | 281 |
285 ThreadState m_threadState = ThreadState::NotStarted; | 282 ThreadState m_threadState = ThreadState::NotStarted; |
286 ExitCode m_exitCode = ExitCode::NotTerminated; | 283 ExitCode m_exitCode = ExitCode::NotTerminated; |
287 | 284 |
288 long long m_forcibleTerminationDelayInMs; | 285 long long m_forcibleTerminationDelayInMs; |
289 | 286 |
290 std::unique_ptr<InspectorTaskRunner> m_inspectorTaskRunner; | 287 std::unique_ptr<InspectorTaskRunner> m_inspectorTaskRunner; |
291 | 288 |
292 RefPtr<WorkerLoaderProxy> m_workerLoaderProxy; | 289 RefPtr<WorkerLoaderProxy> m_workerLoaderProxy; |
293 WorkerReportingProxy& m_workerReportingProxy; | 290 WorkerReportingProxy& m_workerReportingProxy; |
294 CrossThreadPersistent<ParentFrameTaskRunners> m_parentFrameTaskRunners; | 291 Persistent<FrameTaskRunnersHolder> m_frameTaskRunners; |
295 | 292 |
296 // This lock protects |m_globalScope|, |m_requestedToTerminate|, | 293 // This lock protects |m_globalScope|, |m_requestedToTerminate|, |
297 // |m_threadState|, |m_runningDebuggerTask| and |m_exitCode|. | 294 // |m_threadState|, |m_runningDebuggerTask| and |m_exitCode|. |
298 Mutex m_threadStateMutex; | 295 Mutex m_threadStateMutex; |
299 | 296 |
300 CrossThreadPersistent<ConsoleMessageStorage> m_consoleMessageStorage; | 297 CrossThreadPersistent<ConsoleMessageStorage> m_consoleMessageStorage; |
301 CrossThreadPersistent<WorkerOrWorkletGlobalScope> m_globalScope; | 298 CrossThreadPersistent<WorkerOrWorkletGlobalScope> m_globalScope; |
302 CrossThreadPersistent<WorkerInspectorController> m_workerInspectorController; | 299 CrossThreadPersistent<WorkerInspectorController> m_workerInspectorController; |
303 | 300 |
304 // Signaled when the thread completes termination on the worker thread. | 301 // Signaled when the thread completes termination on the worker thread. |
305 std::unique_ptr<WaitableEvent> m_shutdownEvent; | 302 std::unique_ptr<WaitableEvent> m_shutdownEvent; |
306 | 303 |
307 // Used to cancel a scheduled forcible termination task. See | 304 // Used to cancel a scheduled forcible termination task. See |
308 // mayForciblyTerminateExecution() for details. | 305 // mayForciblyTerminateExecution() for details. |
309 TaskHandle m_forcibleTerminationTaskHandle; | 306 TaskHandle m_forcibleTerminationTaskHandle; |
310 | 307 |
311 // Created on the main thread heap, but will be accessed cross-thread | 308 // Created on the main thread heap, but will be accessed cross-thread |
312 // when worker thread posts tasks. | 309 // when worker thread posts tasks. |
313 CrossThreadPersistent<WorkerThreadLifecycleContext> | 310 CrossThreadPersistent<WorkerThreadLifecycleContext> |
314 m_workerThreadLifecycleContext; | 311 m_workerThreadLifecycleContext; |
315 }; | 312 }; |
316 | 313 |
317 } // namespace blink | 314 } // namespace blink |
318 | 315 |
319 #endif // WorkerThread_h | 316 #endif // WorkerThread_h |
OLD | NEW |