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

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

Issue 1184833002: Fix a race condition during worker thread initialization (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: AnyNumber => AtMost Created 5 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
« no previous file with comments | « no previous file | Source/core/workers/WorkerThreadTest.cpp » ('j') | 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) 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 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 V8CacheOptions v8CacheOptions = startupData->m_v8CacheOptions; 207 V8CacheOptions v8CacheOptions = startupData->m_v8CacheOptions;
208 208
209 { 209 {
210 MutexLocker lock(m_threadStateMutex); 210 MutexLocker lock(m_threadStateMutex);
211 211
212 // The worker was terminated before the thread had a chance to run. 212 // The worker was terminated before the thread had a chance to run.
213 if (m_terminated) { 213 if (m_terminated) {
214 // Notify the proxy that the WorkerGlobalScope has been disposed of. 214 // Notify the proxy that the WorkerGlobalScope has been disposed of.
215 // This can free this thread object, hence it must not be touched af terwards. 215 // This can free this thread object, hence it must not be touched af terwards.
216 m_workerReportingProxy.workerThreadTerminated(); 216 m_workerReportingProxy.workerThreadTerminated();
217 // Notify the main thread that it is safe to deallocate our resource s.
218 m_terminationEvent->signal();
217 return; 219 return;
218 } 220 }
219 221
220 m_microtaskRunner = adoptPtr(new WorkerMicrotaskRunner(this)); 222 m_microtaskRunner = adoptPtr(new WorkerMicrotaskRunner(this));
221 initializeBackingThread(); 223 initializeBackingThread();
222 backingThread().addTaskObserver(m_microtaskRunner.get()); 224 backingThread().addTaskObserver(m_microtaskRunner.get());
223 225
224 m_isolate = initializeIsolate(); 226 m_isolate = initializeIsolate();
225 m_workerGlobalScope = createWorkerGlobalScope(startupData); 227 m_workerGlobalScope = createWorkerGlobalScope(startupData);
226 m_workerGlobalScope->scriptLoaded(sourceCode.length(), cachedMetaData.ge t() ? cachedMetaData->size() : 0); 228 m_workerGlobalScope->scriptLoaded(sourceCode.length(), cachedMetaData.ge t() ? cachedMetaData->size() : 0);
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 m_terminated = true; 318 m_terminated = true;
317 319
318 // Signal the thread to notify that the thread's stopping. 320 // Signal the thread to notify that the thread's stopping.
319 if (m_shutdownEvent) 321 if (m_shutdownEvent)
320 m_shutdownEvent->signal(); 322 m_shutdownEvent->signal();
321 323
322 // If the thread has already initiated shut down, just return. 324 // If the thread has already initiated shut down, just return.
323 if (m_shutdown) 325 if (m_shutdown)
324 return; 326 return;
325 327
326 // If the worker thread was never initialized, complete the termination imme diately. 328 // If the worker thread was never initialized, don't start another
327 if (!m_workerGlobalScope) { 329 // shutdown, but still wait for the thread to signal when termination has
328 m_terminationEvent->signal(); 330 // completed.
331 if (!m_workerGlobalScope)
329 return; 332 return;
330 }
331 333
332 // Ensure that tasks are being handled by thread event loop. If script execu tion weren't forbidden, a while(1) loop in JS could keep the thread alive foreve r. 334 // Ensure that tasks are being handled by thread event loop. If script execu tion weren't forbidden, a while(1) loop in JS could keep the thread alive foreve r.
333 m_workerGlobalScope->script()->willScheduleExecutionTermination(); 335 m_workerGlobalScope->script()->willScheduleExecutionTermination();
334 terminateV8Execution(); 336 terminateV8Execution();
335 337
336 InspectorInstrumentation::didKillAllExecutionContextTasks(m_workerGlobalScop e.get()); 338 InspectorInstrumentation::didKillAllExecutionContextTasks(m_workerGlobalScop e.get());
337 m_debuggerMessageQueue.kill(); 339 m_debuggerMessageQueue.kill();
338 backingThread().postTask(FROM_HERE, new Task(threadSafeBind(&WorkerThread::s hutdown, AllowCrossThreadAccess(this)))); 340 backingThread().postTask(FROM_HERE, new Task(threadSafeBind(&WorkerThread::s hutdown, AllowCrossThreadAccess(this))));
339 } 341 }
340 342
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
483 InspectorInstrumentation::didLeaveNestedRunLoop(m_workerGlobalScope.get()); 485 InspectorInstrumentation::didLeaveNestedRunLoop(m_workerGlobalScope.get());
484 } 486 }
485 487
486 void WorkerThread::setWorkerInspectorController(WorkerInspectorController* worke rInspectorController) 488 void WorkerThread::setWorkerInspectorController(WorkerInspectorController* worke rInspectorController)
487 { 489 {
488 MutexLocker locker(m_workerInspectorControllerMutex); 490 MutexLocker locker(m_workerInspectorControllerMutex);
489 m_workerInspectorController = workerInspectorController; 491 m_workerInspectorController = workerInspectorController;
490 } 492 }
491 493
492 } // namespace blink 494 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | Source/core/workers/WorkerThreadTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698