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

Side by Side Diff: Source/web/WebKit.cpp

Issue 1257723002: Simplify ownership of a ThreadState's interruptors. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Switch addInterruptor() to take a PassOwnPtr<> Created 5 years, 5 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
« no previous file with comments | « Source/platform/heap/ThreadState.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2009 Google Inc. All rights reserved. 2 * Copyright (C) 2009 Google 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 are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 } 94 }
95 private: 95 private:
96 WTF::MainThreadFunction* m_function; 96 WTF::MainThreadFunction* m_function;
97 void* m_context; 97 void* m_context;
98 }; 98 };
99 99
100 } // namespace 100 } // namespace
101 101
102 static WebThread::TaskObserver* s_endOfTaskRunner = 0; 102 static WebThread::TaskObserver* s_endOfTaskRunner = 0;
103 static WebThread::TaskObserver* s_pendingGCRunner = 0; 103 static WebThread::TaskObserver* s_pendingGCRunner = 0;
104 static ThreadState::Interruptor* s_messageLoopInterruptor = 0;
105 static ThreadState::Interruptor* s_isolateInterruptor = 0;
106 104
107 // Make sure we are not re-initialized in the same address space. 105 // Make sure we are not re-initialized in the same address space.
108 // Doing so may cause hard to reproduce crashes. 106 // Doing so may cause hard to reproduce crashes.
109 static bool s_webKitInitialized = false; 107 static bool s_webKitInitialized = false;
110 108
111 void initialize(Platform* platform) 109 void initialize(Platform* platform)
112 { 110 {
113 initializeWithoutV8(platform); 111 initializeWithoutV8(platform);
114 112
115 V8Initializer::initializeMainThreadIfNeeded(); 113 V8Initializer::initializeMainThreadIfNeeded();
116 114
117 s_isolateInterruptor = new V8IsolateInterruptor(V8PerIsolateData::mainThread Isolate()); 115 OwnPtr<V8IsolateInterruptor> interruptor = adoptPtr(new V8IsolateInterruptor (V8PerIsolateData::mainThreadIsolate()));
118 ThreadState::current()->addInterruptor(s_isolateInterruptor); 116 ThreadState::current()->addInterruptor(interruptor.release());
119 ThreadState::current()->registerTraceDOMWrappers(V8PerIsolateData::mainThrea dIsolate(), V8GCController::traceDOMWrappers); 117 ThreadState::current()->registerTraceDOMWrappers(V8PerIsolateData::mainThrea dIsolate(), V8GCController::traceDOMWrappers);
120 118
121 // currentThread is null if we are running on a thread without a message loo p. 119 // currentThread is null if we are running on a thread without a message loo p.
122 if (WebThread* currentThread = platform->currentThread()) { 120 if (WebThread* currentThread = platform->currentThread()) {
123 ASSERT(!s_endOfTaskRunner); 121 ASSERT(!s_endOfTaskRunner);
124 s_endOfTaskRunner = new EndOfTaskRunner; 122 s_endOfTaskRunner = new EndOfTaskRunner;
125 currentThread->addTaskObserver(s_endOfTaskRunner); 123 currentThread->addTaskObserver(s_endOfTaskRunner);
126 } 124 }
127 } 125 }
128 126
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 WTF::initializeMainThread(callOnMainThreadFunction); 177 WTF::initializeMainThread(callOnMainThreadFunction);
180 Heap::init(); 178 Heap::init();
181 179
182 ThreadState::attachMainThread(); 180 ThreadState::attachMainThread();
183 // currentThread() is null if we are running on a thread without a message l oop. 181 // currentThread() is null if we are running on a thread without a message l oop.
184 if (WebThread* currentThread = platform->currentThread()) { 182 if (WebThread* currentThread = platform->currentThread()) {
185 ASSERT(!s_pendingGCRunner); 183 ASSERT(!s_pendingGCRunner);
186 s_pendingGCRunner = new PendingGCRunner; 184 s_pendingGCRunner = new PendingGCRunner;
187 currentThread->addTaskObserver(s_pendingGCRunner); 185 currentThread->addTaskObserver(s_pendingGCRunner);
188 186
189 ASSERT(!s_messageLoopInterruptor); 187 OwnPtr<MessageLoopInterruptor> interruptor = adoptPtr(new MessageLoopInt erruptor(currentThread));
190 s_messageLoopInterruptor = new MessageLoopInterruptor(currentThread); 188 ThreadState::current()->addInterruptor(interruptor.release());
191 ThreadState::current()->addInterruptor(s_messageLoopInterruptor);
192 } 189 }
193 190
194 DEFINE_STATIC_LOCAL(ModulesInitializer, initializer, ()); 191 DEFINE_STATIC_LOCAL(ModulesInitializer, initializer, ());
195 initializer.init(); 192 initializer.init();
196 193
197 setIndexedDBClientCreateFunction(IndexedDBClientImpl::create); 194 setIndexedDBClientCreateFunction(IndexedDBClientImpl::create);
198 } 195 }
199 196
200 void shutdown() 197 void shutdown()
201 { 198 {
202 // currentThread() is null if we are running on a thread without a message l oop. 199 // currentThread() is null if we are running on a thread without a message l oop.
203 if (Platform::current()->currentThread()) { 200 if (Platform::current()->currentThread()) {
204 // We don't need to (cannot) remove s_endOfTaskRunner from the current 201 // We don't need to (cannot) remove s_endOfTaskRunner from the current
205 // message loop, because the message loop is already destructed before 202 // message loop, because the message loop is already destructed before
206 // the shutdown() is called. 203 // the shutdown() is called.
207 delete s_endOfTaskRunner; 204 delete s_endOfTaskRunner;
208 s_endOfTaskRunner = 0; 205 s_endOfTaskRunner = 0;
209 } 206 }
210 207
211 ASSERT(s_isolateInterruptor);
212 ThreadState::current()->removeInterruptor(s_isolateInterruptor);
213
214 // currentThread() is null if we are running on a thread without a message l oop. 208 // currentThread() is null if we are running on a thread without a message l oop.
215 if (Platform::current()->currentThread()) { 209 if (Platform::current()->currentThread()) {
216 ASSERT(s_pendingGCRunner); 210 ASSERT(s_pendingGCRunner);
217 delete s_pendingGCRunner; 211 delete s_pendingGCRunner;
218 s_pendingGCRunner = 0; 212 s_pendingGCRunner = 0;
219
220 ASSERT(s_messageLoopInterruptor);
221 ThreadState::current()->removeInterruptor(s_messageLoopInterruptor);
222 delete s_messageLoopInterruptor;
223 s_messageLoopInterruptor = 0;
224 } 213 }
225 214
226 // Shutdown V8-related background threads before V8 is ramped down. Note 215 // Shutdown V8-related background threads before V8 is ramped down. Note
227 // that this will wait the thread to stop its operations. 216 // that this will wait the thread to stop its operations.
228 ScriptStreamerThread::shutdown(); 217 ScriptStreamerThread::shutdown();
229 218
230 v8::Isolate* isolate = V8PerIsolateData::mainThreadIsolate(); 219 v8::Isolate* isolate = V8PerIsolateData::mainThreadIsolate();
231 V8PerIsolateData::willBeDestroyed(isolate); 220 V8PerIsolateData::willBeDestroyed(isolate);
232 221
233 // Make sure we stop WorkerThreads before the main thread's ThreadState 222 // Make sure we stop WorkerThreads before the main thread's ThreadState
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 ASSERT(!reloadPages); 279 ASSERT(!reloadPages);
291 Page::refreshPlugins(); 280 Page::refreshPlugins();
292 } 281 }
293 282
294 void decommitFreeableMemory() 283 void decommitFreeableMemory()
295 { 284 {
296 WTF::Partitions::decommitFreeableMemory(); 285 WTF::Partitions::decommitFreeableMemory();
297 } 286 }
298 287
299 } // namespace blink 288 } // namespace blink
OLDNEW
« no previous file with comments | « Source/platform/heap/ThreadState.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698