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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
51 | 51 |
52 enum WorkerThreadStartMode { | 52 enum WorkerThreadStartMode { |
53 DontPauseWorkerGlobalScopeOnStart, | 53 DontPauseWorkerGlobalScopeOnStart, |
54 PauseWorkerGlobalScopeOnStart | 54 PauseWorkerGlobalScopeOnStart |
55 }; | 55 }; |
56 | 56 |
57 // WorkerThread is a kind of WorkerBackingThread client. Each worker mechanism | 57 // WorkerThread is a kind of WorkerBackingThread client. Each worker mechanism |
58 // can access the lower thread infrastructure via an implementation of this | 58 // can access the lower thread infrastructure via an implementation of this |
59 // abstract class. Multiple WorkerThreads can share one WorkerBackingThread. | 59 // abstract class. Multiple WorkerThreads can share one WorkerBackingThread. |
60 // See WorkerBackingThread.h for more details. | 60 // See WorkerBackingThread.h for more details. |
61 // | |
62 // WorkerThread start and termination must be initiated on the main thread and | |
63 // an actual task is executed on the worker thread. | |
61 class CORE_EXPORT WorkerThread { | 64 class CORE_EXPORT WorkerThread { |
62 public: | 65 public: |
63 virtual ~WorkerThread(); | 66 virtual ~WorkerThread(); |
64 | 67 |
65 // Called on the main thread. | 68 // Called on the main thread. |
66 void start(PassOwnPtr<WorkerThreadStartupData>); | 69 void start(PassOwnPtr<WorkerThreadStartupData>); |
67 void terminate(); | 70 void terminate(); |
68 | 71 |
69 // Called in shutdown sequence on the main thread. Internally calls | 72 // Called in shutdown sequence on the main thread. Internally calls |
70 // terminate() and wait (by *blocking* the calling thread) until the | 73 // terminate() and wait (by *blocking* the calling thread) until the |
71 // worker(s) is/are shut down. | 74 // worker(s) is/are shut down. |
72 void terminateAndWait(); | 75 void terminateAndWait(); |
73 static void terminateAndWaitForAllWorkers(); | 76 static void terminateAndWaitForAllWorkers(); |
74 | 77 |
75 // Called on the worker thread for WorkerGlobleScope::close(). | 78 // Called on the worker thread. Disposes |m_workerGlobalScope|. |
76 void terminateFromWorkerThread(); | 79 void prepareForShutdown(); |
kinuko
2016/05/24 09:07:49
nit: could we make WorkerMicroTaskRunner a private
nhiroki
2016/05/24 13:36:06
Agreed. I'll make a separate CL for this.
nhiroki
2016/05/25 01:58:33
Uploaded a CL: https://codereview.chromium.org/200
| |
77 | 80 |
78 virtual WorkerBackingThread& workerBackingThread() = 0; | 81 virtual WorkerBackingThread& workerBackingThread() = 0; |
79 virtual bool shouldAttachThreadDebugger() const { return true; } | 82 virtual bool shouldAttachThreadDebugger() const { return true; } |
80 v8::Isolate* isolate(); | 83 v8::Isolate* isolate(); |
81 | 84 |
82 // Can be used to wait for this worker thread to terminate. | 85 // Can be used to wait for this worker thread to terminate. |
83 // (This is signaled on the main thread, so it's assumed to be waited on | 86 // (This is signaled on the main thread, so it's assumed to be waited on |
84 // the worker context thread) | 87 // the worker context thread) |
85 WaitableEvent* terminationEvent() { return m_terminationEvent.get(); } | 88 WaitableEvent* terminationEvent() { return m_terminationEvent.get(); } |
86 | 89 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
122 virtual WorkerGlobalScope* createWorkerGlobalScope(PassOwnPtr<WorkerThreadSt artupData>) = 0; | 125 virtual WorkerGlobalScope* createWorkerGlobalScope(PassOwnPtr<WorkerThreadSt artupData>) = 0; |
123 | 126 |
124 // Called on the worker thread. | 127 // Called on the worker thread. |
125 virtual void postInitialize() { } | 128 virtual void postInitialize() { } |
126 | 129 |
127 private: | 130 private: |
128 std::unique_ptr<CrossThreadClosure> createWorkerThreadTask(std::unique_ptr<E xecutionContextTask>, bool isInstrumented); | 131 std::unique_ptr<CrossThreadClosure> createWorkerThreadTask(std::unique_ptr<E xecutionContextTask>, bool isInstrumented); |
129 | 132 |
130 // Called on the worker thread. | 133 // Called on the worker thread. |
131 void initialize(PassOwnPtr<WorkerThreadStartupData>); | 134 void initialize(PassOwnPtr<WorkerThreadStartupData>); |
132 void shutdown(); | |
133 void performTask(std::unique_ptr<ExecutionContextTask>, bool isInstrumented) ; | 135 void performTask(std::unique_ptr<ExecutionContextTask>, bool isInstrumented) ; |
134 void performShutdownTask(); | 136 void performShutdownTask(); |
135 void runDebuggerTask(std::unique_ptr<CrossThreadClosure>); | 137 void runDebuggerTask(std::unique_ptr<CrossThreadClosure>); |
136 void runDebuggerTaskDontWait(); | 138 void runDebuggerTaskDontWait(); |
137 | 139 |
138 bool m_started; | 140 bool m_started = false; |
139 bool m_terminated; | 141 bool m_terminated = false; |
140 bool m_shutdown; | 142 bool m_readyToShutdown = false; |
141 bool m_pausedInDebugger; | 143 bool m_pausedInDebugger = false; |
142 bool m_runningDebuggerTask; | 144 bool m_runningDebuggerTask = false; |
143 bool m_shouldTerminateV8Execution; | 145 bool m_shouldTerminateV8Execution = false; |
146 | |
144 OwnPtr<InspectorTaskRunner> m_inspectorTaskRunner; | 147 OwnPtr<InspectorTaskRunner> m_inspectorTaskRunner; |
145 OwnPtr<WebThread::TaskObserver> m_microtaskRunner; | 148 OwnPtr<WebThread::TaskObserver> m_microtaskRunner; |
146 | 149 |
147 RefPtr<WorkerLoaderProxy> m_workerLoaderProxy; | 150 RefPtr<WorkerLoaderProxy> m_workerLoaderProxy; |
148 WorkerReportingProxy& m_workerReportingProxy; | 151 WorkerReportingProxy& m_workerReportingProxy; |
149 | 152 |
150 // This lock protects |m_workerGlobalScope|, |m_terminated|, |m_shutdown|, | 153 // This lock protects |m_workerGlobalScope|, |m_terminated|, |
151 // |m_runningDebuggerTask|, |m_shouldTerminateV8Execution| and | 154 // |m_readyToShutdown|, |m_runningDebuggerTask|, |
152 // |m_microtaskRunner|. | 155 // |m_shouldTerminateV8Execution| and |m_microtaskRunner|. |
153 Mutex m_threadStateMutex; | 156 Mutex m_threadStateMutex; |
154 | 157 |
155 Persistent<WorkerGlobalScope> m_workerGlobalScope; | 158 Persistent<WorkerGlobalScope> m_workerGlobalScope; |
156 | 159 |
157 // Signaled when the thread starts termination on the main thread. | 160 // Signaled when the thread starts termination on the main thread. |
158 OwnPtr<WaitableEvent> m_terminationEvent; | 161 OwnPtr<WaitableEvent> m_terminationEvent; |
159 | 162 |
160 // Signaled when the thread completes termination on the worker thread. | 163 // Signaled when the thread completes termination on the worker thread. |
161 OwnPtr<WaitableEvent> m_shutdownEvent; | 164 OwnPtr<WaitableEvent> m_shutdownEvent; |
162 }; | 165 }; |
163 | 166 |
164 } // namespace blink | 167 } // namespace blink |
165 | 168 |
166 #endif // WorkerThread_h | 169 #endif // WorkerThread_h |
OLD | NEW |