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 29 matching lines...) Expand all Loading... |
40 #include "wtf/PassRefPtr.h" | 40 #include "wtf/PassRefPtr.h" |
41 #include "wtf/RefCounted.h" | 41 #include "wtf/RefCounted.h" |
42 #include <v8.h> | 42 #include <v8.h> |
43 | 43 |
44 namespace blink { | 44 namespace blink { |
45 | 45 |
46 class WebWaitableEvent; | 46 class WebWaitableEvent; |
47 class WorkerGlobalScope; | 47 class WorkerGlobalScope; |
48 class WorkerInspectorController; | 48 class WorkerInspectorController; |
49 class WorkerReportingProxy; | 49 class WorkerReportingProxy; |
50 class WorkerSharedTimer; | |
51 class WorkerThreadShutdownFinishTask; | 50 class WorkerThreadShutdownFinishTask; |
52 class WorkerThreadStartupData; | 51 class WorkerThreadStartupData; |
53 class WorkerThreadTask; | 52 class WorkerThreadTask; |
54 | 53 |
55 enum WorkerThreadStartMode { | 54 enum WorkerThreadStartMode { |
56 DontPauseWorkerGlobalScopeOnStart, | 55 DontPauseWorkerGlobalScopeOnStart, |
57 PauseWorkerGlobalScopeOnStart | 56 PauseWorkerGlobalScopeOnStart |
58 }; | 57 }; |
59 | 58 |
60 class CORE_EXPORT WorkerThread : public RefCounted<WorkerThread> { | 59 class CORE_EXPORT WorkerThread : public RefCounted<WorkerThread> { |
(...skipping 30 matching lines...) Expand all Loading... |
91 void postDebuggerTask(const WebTraceLocation&, PassOwnPtr<ExecutionContextTa
sk>); | 90 void postDebuggerTask(const WebTraceLocation&, PassOwnPtr<ExecutionContextTa
sk>); |
92 | 91 |
93 enum WaitMode { WaitForMessage, DontWaitForMessage }; | 92 enum WaitMode { WaitForMessage, DontWaitForMessage }; |
94 MessageQueueWaitResult runDebuggerTask(WaitMode = WaitForMessage); | 93 MessageQueueWaitResult runDebuggerTask(WaitMode = WaitForMessage); |
95 | 94 |
96 // These methods should be called if the holder of the thread is | 95 // These methods should be called if the holder of the thread is |
97 // going to call runDebuggerTask in a loop. | 96 // going to call runDebuggerTask in a loop. |
98 void willEnterNestedLoop(); | 97 void willEnterNestedLoop(); |
99 void didLeaveNestedLoop(); | 98 void didLeaveNestedLoop(); |
100 | 99 |
| 100 // Prevent execution of all non-shutdown tasks. |
| 101 void preShutdown(); |
| 102 |
101 WorkerGlobalScope* workerGlobalScope() const { return m_workerGlobalScope.ge
t(); } | 103 WorkerGlobalScope* workerGlobalScope() const { return m_workerGlobalScope.ge
t(); } |
102 bool terminated(); | 104 |
| 105 // Virtual for testing. |
| 106 virtual bool terminated(); |
103 | 107 |
104 // Number of active worker threads. | 108 // Number of active worker threads. |
105 static unsigned workerThreadCount(); | 109 static unsigned workerThreadCount(); |
106 | 110 |
107 PlatformThreadId platformThreadId() const; | 111 PlatformThreadId platformThreadId() const; |
108 | 112 |
109 void interruptAndDispatchInspectorCommands(); | 113 void interruptAndDispatchInspectorCommands(); |
110 void setWorkerInspectorController(WorkerInspectorController*); | 114 void setWorkerInspectorController(WorkerInspectorController*); |
111 | 115 |
112 protected: | 116 protected: |
113 WorkerThread(const char* threadName, PassRefPtr<WorkerLoaderProxy>, WorkerRe
portingProxy&, PassOwnPtr<WorkerThreadStartupData>); | 117 WorkerThread(const char* threadName, PassRefPtr<WorkerLoaderProxy>, WorkerRe
portingProxy&, PassOwnPtr<WorkerThreadStartupData>); |
114 | 118 |
115 // Factory method for creating a new worker context for the thread. | 119 // Factory method for creating a new worker context for the thread. |
116 virtual PassRefPtrWillBeRawPtr<WorkerGlobalScope> createWorkerGlobalScope(Pa
ssOwnPtr<WorkerThreadStartupData>) = 0; | 120 virtual PassRefPtrWillBeRawPtr<WorkerGlobalScope> createWorkerGlobalScope(Pa
ssOwnPtr<WorkerThreadStartupData>) = 0; |
117 | 121 |
118 virtual void postInitialize() { } | 122 virtual void postInitialize() { } |
119 | 123 |
120 virtual v8::Isolate* initializeIsolate(); | 124 virtual v8::Isolate* initializeIsolate(); |
121 virtual void willDestroyIsolate(); | 125 virtual void willDestroyIsolate(); |
122 virtual void destroyIsolate(); | 126 virtual void destroyIsolate(); |
123 virtual void terminateV8Execution(); | 127 virtual void terminateV8Execution(); |
124 | 128 |
| 129 // This is protected virtual for testing. |
| 130 virtual bool doIdleGc(double deadlineSeconds); |
| 131 |
| 132 WebScheduler* schedulerForTesting() const |
| 133 { |
| 134 return m_webScheduler; |
| 135 } |
| 136 |
| 137 WebThreadSupportingGC* threadForTesting() const |
| 138 { |
| 139 return m_thread.get(); |
| 140 } |
| 141 |
125 private: | 142 private: |
126 friend class WorkerSharedTimer; | 143 friend class WorkerThreadIdleTask; |
127 friend class WorkerThreadShutdownFinishTask; | 144 friend class WorkerThreadShutdownFinishTask; |
128 | 145 |
129 void stopInShutdownSequence(); | 146 void stopInShutdownSequence(); |
130 void stopInternal(); | 147 void stopInternal(); |
131 | 148 |
132 void initialize(); | 149 void initialize(); |
133 void cleanup(); | 150 void cleanup(); |
134 void idleHandler(); | 151 void idleTask(double deadlineSeconds); |
135 void postDelayedTask(PassOwnPtr<ExecutionContextTask>, long long delayMs); | 152 void postDelayedTask(PassOwnPtr<ExecutionContextTask>, long long delayMs); |
136 void postDelayedTask(const WebTraceLocation&, PassOwnPtr<ExecutionContextTas
k>, long long delayMs); | 153 void postDelayedTask(const WebTraceLocation&, PassOwnPtr<ExecutionContextTas
k>, long long delayMs); |
137 | 154 |
138 const char* m_threadName; | 155 const char* m_threadName; |
139 bool m_terminated; | 156 bool m_terminated; |
140 MessageQueue<WorkerThreadTask> m_debuggerMessageQueue; | 157 MessageQueue<WorkerThreadTask> m_debuggerMessageQueue; |
141 OwnPtr<WebThread::TaskObserver> m_microtaskRunner; | 158 OwnPtr<WebThread::TaskObserver> m_microtaskRunner; |
142 | 159 |
143 RefPtr<WorkerLoaderProxy> m_workerLoaderProxy; | 160 RefPtr<WorkerLoaderProxy> m_workerLoaderProxy; |
144 WorkerReportingProxy& m_workerReportingProxy; | 161 WorkerReportingProxy& m_workerReportingProxy; |
145 | 162 |
146 RefPtrWillBePersistent<WorkerInspectorController> m_workerInspectorControlle
r; | 163 RefPtrWillBePersistent<WorkerInspectorController> m_workerInspectorControlle
r; |
147 Mutex m_workerInspectorControllerMutex; | 164 Mutex m_workerInspectorControllerMutex; |
148 | 165 |
149 Mutex m_threadCreationMutex; | 166 Mutex m_threadCreationMutex; |
150 RefPtrWillBePersistent<WorkerGlobalScope> m_workerGlobalScope; | 167 RefPtrWillBePersistent<WorkerGlobalScope> m_workerGlobalScope; |
151 OwnPtr<WorkerThreadStartupData> m_startupData; | 168 OwnPtr<WorkerThreadStartupData> m_startupData; |
152 | 169 |
153 v8::Isolate* m_isolate; | 170 v8::Isolate* m_isolate; |
154 OwnPtr<V8IsolateInterruptor> m_interruptor; | 171 OwnPtr<V8IsolateInterruptor> m_interruptor; |
155 | 172 |
156 // Used to signal thread shutdown. | 173 // Used to signal thread shutdown. |
157 OwnPtr<WebWaitableEvent> m_shutdownEvent; | 174 OwnPtr<WebWaitableEvent> m_shutdownEvent; |
158 | 175 |
159 // Used to signal thread termination. | 176 // Used to signal thread termination. |
160 OwnPtr<WebWaitableEvent> m_terminationEvent; | 177 OwnPtr<WebWaitableEvent> m_terminationEvent; |
161 | 178 |
| 179 RawPtr<WebScheduler> m_webScheduler; // NOT OWNED. |
| 180 |
| 181 Mutex m_preShutdownMutex; |
| 182 bool m_preShutdown; |
| 183 |
162 // FIXME: This has to be last because of crbug.com/401397 - the | 184 // FIXME: This has to be last because of crbug.com/401397 - the |
163 // WorkerThread might get deleted before it had a chance to properly | 185 // WorkerThread might get deleted before it had a chance to properly |
164 // shut down. By deleting the WebThread first, we can guarantee that | 186 // shut down. By deleting the WebThread first, we can guarantee that |
165 // no pending tasks on the thread might want to access any of the other | 187 // no pending tasks on the thread might want to access any of the other |
166 // members during the WorkerThread's destruction. | 188 // members during the WorkerThread's destruction. |
167 OwnPtr<WebThreadSupportingGC> m_thread; | 189 OwnPtr<WebThreadSupportingGC> m_thread; |
168 }; | 190 }; |
169 | 191 |
170 } // namespace blink | 192 } // namespace blink |
171 | 193 |
172 #endif // WorkerThread_h | 194 #endif // WorkerThread_h |
OLD | NEW |