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 #include "config.h" | 27 #include "config.h" |
28 | 28 |
29 #include "core/workers/WorkerThread.h" | 29 #include "core/workers/WorkerThread.h" |
30 | 30 |
31 #include "bindings/v8/ScriptSourceCode.h" | 31 #include "bindings/v8/ScriptSourceCode.h" |
32 #include "core/inspector/InspectorInstrumentation.h" | 32 #include "core/inspector/InspectorInstrumentation.h" |
33 #include "core/inspector/WorkerDebuggerAgent.h" | |
34 #include "core/inspector/WorkerInspectorController.h" | |
33 #include "core/workers/DedicatedWorkerGlobalScope.h" | 35 #include "core/workers/DedicatedWorkerGlobalScope.h" |
34 #include "core/workers/WorkerClients.h" | 36 #include "core/workers/WorkerClients.h" |
35 #include "core/workers/WorkerReportingProxy.h" | 37 #include "core/workers/WorkerReportingProxy.h" |
36 #include "core/workers/WorkerThreadStartupData.h" | 38 #include "core/workers/WorkerThreadStartupData.h" |
37 #include "platform/PlatformThreadData.h" | 39 #include "platform/PlatformThreadData.h" |
38 #include "platform/heap/ThreadState.h" | 40 #include "platform/heap/ThreadState.h" |
39 #include "platform/weborigin/KURL.h" | 41 #include "platform/weborigin/KURL.h" |
40 #include "public/platform/Platform.h" | 42 #include "public/platform/Platform.h" |
41 #include "public/platform/WebWaitableEvent.h" | 43 #include "public/platform/WebWaitableEvent.h" |
42 #include "public/platform/WebWorkerRunLoop.h" | 44 #include "public/platform/WebWorkerRunLoop.h" |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
95 m_threadID = createThread(WorkerThread::workerThreadStart, this, "WebCore: W orker"); | 97 m_threadID = createThread(WorkerThread::workerThreadStart, this, "WebCore: W orker"); |
96 | 98 |
97 return m_threadID; | 99 return m_threadID; |
98 } | 100 } |
99 | 101 |
100 void WorkerThread::workerThreadStart(void* thread) | 102 void WorkerThread::workerThreadStart(void* thread) |
101 { | 103 { |
102 static_cast<WorkerThread*>(thread)->workerThread(); | 104 static_cast<WorkerThread*>(thread)->workerThread(); |
103 } | 105 } |
104 | 106 |
107 void WorkerThread::interruptAndDispatchInspectorCommands() | |
108 { | |
109 MutexLocker locker(m_threadShutdownMutex); | |
110 if (!m_workerGlobalScope) | |
111 return; | |
112 if (WorkerInspectorController* inspectorController = m_workerGlobalScope->wo rkerInspectorController()) | |
yurys
2014/06/26 11:04:30
WorkerGlobalScope::clearInspector may be executing
horo
2014/06/27 06:36:05
I agree with yurys.
But it may be good to add "if
| |
113 inspectorController->interruptAndDispatchInspectorCommands(); | |
114 } | |
115 | |
105 void WorkerThread::workerThread() | 116 void WorkerThread::workerThread() |
106 { | 117 { |
107 KURL scriptURL = m_startupData->m_scriptURL; | 118 KURL scriptURL = m_startupData->m_scriptURL; |
108 String sourceCode = m_startupData->m_sourceCode; | 119 String sourceCode = m_startupData->m_sourceCode; |
109 WorkerThreadStartMode startMode = m_startupData->m_startMode; | 120 WorkerThreadStartMode startMode = m_startupData->m_startMode; |
110 | |
111 { | 121 { |
112 MutexLocker lock(m_threadCreationMutex); | 122 MutexLocker lock(m_threadCreationMutex); |
113 ThreadState::attach(); | 123 ThreadState::attach(); |
114 m_workerGlobalScope = createWorkerGlobalScope(m_startupData.release()); | 124 m_workerGlobalScope = createWorkerGlobalScope(m_startupData.release()); |
115 m_runLoop.setWorkerGlobalScope(workerGlobalScope()); | 125 m_runLoop.setWorkerGlobalScope(workerGlobalScope()); |
116 | 126 |
117 if (m_runLoop.terminated()) { | 127 if (m_runLoop.terminated()) { |
118 // The worker was terminated before the thread had a chance to run. Since the context didn't exist yet, | 128 // The worker was terminated before the thread had a chance to run. Since the context didn't exist yet, |
119 // forbidExecution() couldn't be called from stop(). | 129 // forbidExecution() couldn't be called from stop(). |
120 m_workerGlobalScope->script()->forbidExecution(); | 130 m_workerGlobalScope->script()->forbidExecution(); |
(...skipping 12 matching lines...) Expand all Loading... | |
133 InspectorInstrumentation::willEvaluateWorkerScript(workerGlobalScope(), star tMode); | 143 InspectorInstrumentation::willEvaluateWorkerScript(workerGlobalScope(), star tMode); |
134 script->evaluate(ScriptSourceCode(sourceCode, scriptURL)); | 144 script->evaluate(ScriptSourceCode(sourceCode, scriptURL)); |
135 | 145 |
136 runEventLoop(); | 146 runEventLoop(); |
137 | 147 |
138 // This should be called before we start the shutdown procedure. | 148 // This should be called before we start the shutdown procedure. |
139 workerReportingProxy().willDestroyWorkerGlobalScope(); | 149 workerReportingProxy().willDestroyWorkerGlobalScope(); |
140 | 150 |
141 ThreadIdentifier threadID = m_threadID; | 151 ThreadIdentifier threadID = m_threadID; |
142 | 152 |
143 // The below assignment will destroy the context, which will in turn notify messaging proxy. | 153 { |
144 // We cannot let any objects survive past thread exit, because no other thre ad will run GC or otherwise destroy them. | 154 MutexLocker locker(m_threadShutdownMutex); |
145 // If Oilpan is enabled, we detach of the context/global scope, with the fin al heap cleanup below sweeping it out. | 155 // The below assignment will destroy the context, which will in turn not ify messaging proxy. |
156 // We cannot let any objects survive past thread exit, because no other thread will run GC or otherwise destroy them. | |
157 // If Oilpan is enabled, we detach of the context/global scope, with the final heap cleanup below sweeping it out. | |
146 #if !ENABLE(OILPAN) | 158 #if !ENABLE(OILPAN) |
147 ASSERT(m_workerGlobalScope->hasOneRef()); | 159 ASSERT(m_workerGlobalScope->hasOneRef()); |
148 #endif | 160 #endif |
149 m_workerGlobalScope->dispose(); | 161 m_workerGlobalScope->dispose(); |
150 m_workerGlobalScope = nullptr; | 162 m_workerGlobalScope = nullptr; |
163 } | |
151 | 164 |
152 // Detach the ThreadState, cleaning out the thread's heap by | 165 // Detach the ThreadState, cleaning out the thread's heap by |
153 // performing a final GC. The cleanup operation will at the end | 166 // performing a final GC. The cleanup operation will at the end |
154 // assert that the heap is empty. If the heap does not become | 167 // assert that the heap is empty. If the heap does not become |
155 // empty, there are still pointers into the heap and those | 168 // empty, there are still pointers into the heap and those |
156 // pointers will be dangling after thread termination because we | 169 // pointers will be dangling after thread termination because we |
157 // are destroying the heap. It is important to detach while the | 170 // are destroying the heap. It is important to detach while the |
158 // thread is still valid. In particular, finalizers for objects in | 171 // thread is still valid. In particular, finalizers for objects in |
159 // the heap for this thread will need to access thread local data. | 172 // the heap for this thread will need to access thread local data. |
160 ThreadState::detach(); | 173 ThreadState::detach(); |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
240 } | 253 } |
241 m_runLoop.terminate(); | 254 m_runLoop.terminate(); |
242 } | 255 } |
243 | 256 |
244 bool WorkerThread::isCurrentThread() const | 257 bool WorkerThread::isCurrentThread() const |
245 { | 258 { |
246 return m_threadID == currentThread(); | 259 return m_threadID == currentThread(); |
247 } | 260 } |
248 | 261 |
249 } // namespace WebCore | 262 } // namespace WebCore |
OLD | NEW |