Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(474)

Side by Side Diff: Source/core/workers/WorkerThread.cpp

Issue 307943002: Oilpan: Prepare moving InspectorController and InspectorAgents to oilpan. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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
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 WorkerInspectorController* inspectorController = m_workerGlobalScope->worker InspectorController();
113 if (!inspectorController)
114 return;
115 if (WorkerDebuggerAgent* debuggerAgent = inspectorController->workerDebugger Agent())
yurys 2014/06/25 06:11:23 This check should always be true as the agent is c
116 debuggerAgent->interruptAndDispatchInspectorCommands(this);
117 }
118
105 void WorkerThread::workerThread() 119 void WorkerThread::workerThread()
106 { 120 {
107 KURL scriptURL = m_startupData->m_scriptURL; 121 KURL scriptURL = m_startupData->m_scriptURL;
108 String sourceCode = m_startupData->m_sourceCode; 122 String sourceCode = m_startupData->m_sourceCode;
109 WorkerThreadStartMode startMode = m_startupData->m_startMode; 123 WorkerThreadStartMode startMode = m_startupData->m_startMode;
110
111 { 124 {
112 MutexLocker lock(m_threadCreationMutex); 125 MutexLocker lock(m_threadCreationMutex);
113 ThreadState::attach(); 126 ThreadState::attach();
114 m_workerGlobalScope = createWorkerGlobalScope(m_startupData.release()); 127 m_workerGlobalScope = createWorkerGlobalScope(m_startupData.release());
115 m_runLoop.setWorkerGlobalScope(workerGlobalScope()); 128 m_runLoop.setWorkerGlobalScope(workerGlobalScope());
116 129
117 if (m_runLoop.terminated()) { 130 if (m_runLoop.terminated()) {
118 // The worker was terminated before the thread had a chance to run. Since the context didn't exist yet, 131 // 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(). 132 // forbidExecution() couldn't be called from stop().
120 m_workerGlobalScope->script()->forbidExecution(); 133 m_workerGlobalScope->script()->forbidExecution();
(...skipping 12 matching lines...) Expand all
133 InspectorInstrumentation::willEvaluateWorkerScript(workerGlobalScope(), star tMode); 146 InspectorInstrumentation::willEvaluateWorkerScript(workerGlobalScope(), star tMode);
134 script->evaluate(ScriptSourceCode(sourceCode, scriptURL)); 147 script->evaluate(ScriptSourceCode(sourceCode, scriptURL));
135 148
136 runEventLoop(); 149 runEventLoop();
137 150
138 // This should be called before we start the shutdown procedure. 151 // This should be called before we start the shutdown procedure.
139 workerReportingProxy().willDestroyWorkerGlobalScope(); 152 workerReportingProxy().willDestroyWorkerGlobalScope();
140 153
141 ThreadIdentifier threadID = m_threadID; 154 ThreadIdentifier threadID = m_threadID;
142 155
143 // The below assignment will destroy the context, which will in turn notify messaging proxy. 156 {
144 // We cannot let any objects survive past thread exit, because no other thre ad will run GC or otherwise destroy them. 157 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. 158 // The below assignment will destroy the context, which will in turn not ify messaging proxy.
159 // We cannot let any objects survive past thread exit, because no other thread will run GC or otherwise destroy them.
160 // If Oilpan is enabled, we detach of the context/global scope, with the final heap cleanup below sweeping it out.
146 #if !ENABLE(OILPAN) 161 #if !ENABLE(OILPAN)
147 ASSERT(m_workerGlobalScope->hasOneRef()); 162 ASSERT(m_workerGlobalScope->hasOneRef());
148 #endif 163 #endif
149 m_workerGlobalScope->dispose(); 164 m_workerGlobalScope->dispose();
150 m_workerGlobalScope = nullptr; 165 m_workerGlobalScope = nullptr;
166 }
151 167
152 // Detach the ThreadState, cleaning out the thread's heap by 168 // Detach the ThreadState, cleaning out the thread's heap by
153 // performing a final GC. The cleanup operation will at the end 169 // performing a final GC. The cleanup operation will at the end
154 // assert that the heap is empty. If the heap does not become 170 // assert that the heap is empty. If the heap does not become
155 // empty, there are still pointers into the heap and those 171 // empty, there are still pointers into the heap and those
156 // pointers will be dangling after thread termination because we 172 // pointers will be dangling after thread termination because we
157 // are destroying the heap. It is important to detach while the 173 // are destroying the heap. It is important to detach while the
158 // thread is still valid. In particular, finalizers for objects in 174 // thread is still valid. In particular, finalizers for objects in
159 // the heap for this thread will need to access thread local data. 175 // the heap for this thread will need to access thread local data.
160 ThreadState::detach(); 176 ThreadState::detach();
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 } 256 }
241 m_runLoop.terminate(); 257 m_runLoop.terminate();
242 } 258 }
243 259
244 bool WorkerThread::isCurrentThread() const 260 bool WorkerThread::isCurrentThread() const
245 { 261 {
246 return m_threadID == currentThread(); 262 return m_threadID == currentThread();
247 } 263 }
248 264
249 } // namespace WebCore 265 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698