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

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

Issue 462423003: WorkerThread should not start execution if WorkerThread::stop is already called (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 4 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 | 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) 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 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 MutexLocker locker(m_workerInspectorControllerMutex); 233 MutexLocker locker(m_workerInspectorControllerMutex);
234 if (m_workerInspectorController) 234 if (m_workerInspectorController)
235 m_workerInspectorController->interruptAndDispatchInspectorCommands(); 235 m_workerInspectorController->interruptAndDispatchInspectorCommands();
236 } 236 }
237 237
238 void WorkerThread::initialize() 238 void WorkerThread::initialize()
239 { 239 {
240 KURL scriptURL = m_startupData->m_scriptURL; 240 KURL scriptURL = m_startupData->m_scriptURL;
241 String sourceCode = m_startupData->m_sourceCode; 241 String sourceCode = m_startupData->m_sourceCode;
242 WorkerThreadStartMode startMode = m_startupData->m_startMode; 242 WorkerThreadStartMode startMode = m_startupData->m_startMode;
243 m_microtaskRunner = adoptPtr(new MicrotaskRunner);
244 m_thread->addTaskObserver(m_microtaskRunner.get());
245 243
246 { 244 {
247 MutexLocker lock(m_threadCreationMutex); 245 MutexLocker lock(m_threadCreationMutex);
248 246
247 // The worker was terminated before the thread had a chance to run.
248 if (m_terminated) {
249 // Notify the proxy that the WorkerGlobalScope has been disposed of.
250 // This can free this thread object, hence it must not be touched af terwards.
251 m_workerReportingProxy.workerGlobalScopeDestroyed();
haraken 2014/08/13 04:48:54 I think that the name "workerGlobalScopeDestroyed"
252 return;
253 }
254
255 m_microtaskRunner = adoptPtr(new MicrotaskRunner);
256 m_thread->addTaskObserver(m_microtaskRunner.get());
249 m_pendingGCRunner = adoptPtr(new PendingGCRunner); 257 m_pendingGCRunner = adoptPtr(new PendingGCRunner);
250 m_messageLoopInterruptor = adoptPtr(new MessageLoopInterruptor(m_thread. get())); 258 m_messageLoopInterruptor = adoptPtr(new MessageLoopInterruptor(m_thread. get()));
251 m_thread->addTaskObserver(m_pendingGCRunner.get()); 259 m_thread->addTaskObserver(m_pendingGCRunner.get());
252 ThreadState::attach(); 260 ThreadState::attach();
253 ThreadState::current()->addInterruptor(m_messageLoopInterruptor.get()); 261 ThreadState::current()->addInterruptor(m_messageLoopInterruptor.get());
254 m_workerGlobalScope = createWorkerGlobalScope(m_startupData.release()); 262 m_workerGlobalScope = createWorkerGlobalScope(m_startupData.release());
255 263
256 m_sharedTimer = adoptPtr(new WorkerSharedTimer(this)); 264 m_sharedTimer = adoptPtr(new WorkerSharedTimer(this));
257 PlatformThreadData::current().threadTimers().setSharedTimer(m_sharedTime r.get()); 265 PlatformThreadData::current().threadTimers().setSharedTimer(m_sharedTime r.get());
258
259 if (m_terminated) {
260 // The worker was terminated before the thread had a chance to run. Since the context didn't exist yet,
261 // forbidExecution() couldn't be called from stop().
262 m_workerGlobalScope->script()->forbidExecution();
263 }
264 } 266 }
265 267
266 // The corresponding call to didStopWorkerRunLoop is in 268 // The corresponding call to didStopWorkerRunLoop is in
267 // ~WorkerScriptController. 269 // ~WorkerScriptController.
268 blink::Platform::current()->didStartWorkerRunLoop(blink::WebWorkerRunLoop(th is)); 270 blink::Platform::current()->didStartWorkerRunLoop(blink::WebWorkerRunLoop(th is));
269 271
270 // Notify proxy that a new WorkerGlobalScope has been created and started. 272 // Notify proxy that a new WorkerGlobalScope has been created and started.
271 m_workerReportingProxy.workerGlobalScopeStarted(m_workerGlobalScope.get()); 273 m_workerReportingProxy.workerGlobalScopeStarted(m_workerGlobalScope.get());
272 274
273 WorkerScriptController* script = m_workerGlobalScope->script(); 275 WorkerScriptController* script = m_workerGlobalScope->script();
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 { 373 {
372 // Prevent the deadlock between GC and an attempt to stop a thread. 374 // Prevent the deadlock between GC and an attempt to stop a thread.
373 ThreadState::SafePointScope safePointScope(ThreadState::HeapPointersOnStack) ; 375 ThreadState::SafePointScope safePointScope(ThreadState::HeapPointersOnStack) ;
374 376
375 // Protect against this method and initialize() racing each other. 377 // Protect against this method and initialize() racing each other.
376 MutexLocker lock(m_threadCreationMutex); 378 MutexLocker lock(m_threadCreationMutex);
377 379
378 // If stop has already been called, just return. 380 // If stop has already been called, just return.
379 if (m_terminated) 381 if (m_terminated)
380 return; 382 return;
383 m_terminated = true;
381 384
382 // Signal the thread to notify that the thread's stopping. 385 // Signal the thread to notify that the thread's stopping.
383 if (m_shutdownEvent) 386 if (m_shutdownEvent)
384 m_shutdownEvent->signal(); 387 m_shutdownEvent->signal();
385 388
386 if (!m_workerGlobalScope) 389 if (!m_workerGlobalScope)
387 return; 390 return;
388 391
389 // 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. 392 // 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.
390 m_workerGlobalScope->script()->scheduleExecutionTermination(); 393 m_workerGlobalScope->script()->scheduleExecutionTermination();
391 m_workerGlobalScope->wasRequestedToTerminate(); 394 m_workerGlobalScope->wasRequestedToTerminate();
392 InspectorInstrumentation::didKillAllExecutionContextTasks(m_workerGlobalScop e.get()); 395 InspectorInstrumentation::didKillAllExecutionContextTasks(m_workerGlobalScop e.get());
393 m_debuggerMessageQueue.kill(); 396 m_debuggerMessageQueue.kill();
394 postTask(WorkerThreadShutdownStartTask::create()); 397 postTask(WorkerThreadShutdownStartTask::create());
395 m_terminated = true;
396 } 398 }
397 399
398 bool WorkerThread::isCurrentThread() const 400 bool WorkerThread::isCurrentThread() const
399 { 401 {
400 return m_thread && m_thread->isCurrentThread(); 402 return m_thread && m_thread->isCurrentThread();
401 } 403 }
402 404
403 void WorkerThread::idleHandler() 405 void WorkerThread::idleHandler()
404 { 406 {
405 ASSERT(m_workerGlobalScope.get()); 407 ASSERT(m_workerGlobalScope.get());
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
464 InspectorInstrumentation::didLeaveNestedRunLoop(m_workerGlobalScope.get()); 466 InspectorInstrumentation::didLeaveNestedRunLoop(m_workerGlobalScope.get());
465 } 467 }
466 468
467 void WorkerThread::setWorkerInspectorController(WorkerInspectorController* worke rInspectorController) 469 void WorkerThread::setWorkerInspectorController(WorkerInspectorController* worke rInspectorController)
468 { 470 {
469 MutexLocker locker(m_workerInspectorControllerMutex); 471 MutexLocker locker(m_workerInspectorControllerMutex);
470 m_workerInspectorController = workerInspectorController; 472 m_workerInspectorController = workerInspectorController;
471 } 473 }
472 474
473 } // namespace blink 475 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698