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

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

Issue 2025783002: Worker: Introduce an observation mechanism for WorkerThread termination (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@delayed_task
Patch Set: Stop tracing CrossThread(Weak)Persistents Created 4 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
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 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 DEFINE_THREAD_SAFE_STATIC_LOCAL(Mutex, mutex, new Mutex); 147 DEFINE_THREAD_SAFE_STATIC_LOCAL(Mutex, mutex, new Mutex);
148 return mutex; 148 return mutex;
149 } 149 }
150 150
151 static HashSet<WorkerThread*>& workerThreads() 151 static HashSet<WorkerThread*>& workerThreads()
152 { 152 {
153 DEFINE_STATIC_LOCAL(HashSet<WorkerThread*>, threads, ()); 153 DEFINE_STATIC_LOCAL(HashSet<WorkerThread*>, threads, ());
154 return threads; 154 return threads;
155 } 155 }
156 156
157 WorkerThreadContext::WorkerThreadContext()
158 {
159 DCHECK(isMainThread());
160 }
161
162 WorkerThreadContext::~WorkerThreadContext()
163 {
164 DCHECK(isMainThread());
165 }
166
167 void WorkerThreadContext::notifyContextDestroyed()
168 {
169 DCHECK(isMainThread());
170 DCHECK(!m_wasContextDestroyed);
171 m_wasContextDestroyed = true;
172 LifecycleNotifier::notifyContextDestroyed();
173 }
174
157 WorkerThread::~WorkerThread() 175 WorkerThread::~WorkerThread()
158 { 176 {
159 DCHECK(isMainThread()); 177 DCHECK(isMainThread());
160 MutexLocker lock(threadSetMutex()); 178 MutexLocker lock(threadSetMutex());
161 DCHECK(workerThreads().contains(this)); 179 DCHECK(workerThreads().contains(this));
162 workerThreads().remove(this); 180 workerThreads().remove(this);
163 181
164 DCHECK_NE(ExitCode::NotTerminated, m_exitCode); 182 DCHECK_NE(ExitCode::NotTerminated, m_exitCode);
165 DEFINE_THREAD_SAFE_STATIC_LOCAL(EnumerationHistogram, exitCodeHistogram, new EnumerationHistogram("WorkerThread.ExitCode", static_cast<int>(ExitCode::LastEn um))); 183 DEFINE_THREAD_SAFE_STATIC_LOCAL(EnumerationHistogram, exitCodeHistogram, new EnumerationHistogram("WorkerThread.ExitCode", static_cast<int>(ExitCode::LastEn um)));
166 exitCodeHistogram.count(static_cast<int>(m_exitCode)); 184 exitCodeHistogram.count(static_cast<int>(m_exitCode));
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 : m_forceTerminationDelayInMs(kForceTerminationDelayInMs) 318 : m_forceTerminationDelayInMs(kForceTerminationDelayInMs)
301 , m_inspectorTaskRunner(adoptPtr(new InspectorTaskRunner())) 319 , m_inspectorTaskRunner(adoptPtr(new InspectorTaskRunner()))
302 , m_workerLoaderProxy(workerLoaderProxy) 320 , m_workerLoaderProxy(workerLoaderProxy)
303 , m_workerReportingProxy(workerReportingProxy) 321 , m_workerReportingProxy(workerReportingProxy)
304 , m_terminationEvent(adoptPtr(new WaitableEvent( 322 , m_terminationEvent(adoptPtr(new WaitableEvent(
305 WaitableEvent::ResetPolicy::Manual, 323 WaitableEvent::ResetPolicy::Manual,
306 WaitableEvent::InitialState::NonSignaled))) 324 WaitableEvent::InitialState::NonSignaled)))
307 , m_shutdownEvent(adoptPtr(new WaitableEvent( 325 , m_shutdownEvent(adoptPtr(new WaitableEvent(
308 WaitableEvent::ResetPolicy::Manual, 326 WaitableEvent::ResetPolicy::Manual,
309 WaitableEvent::InitialState::NonSignaled))) 327 WaitableEvent::InitialState::NonSignaled)))
328 , m_workerThreadContext(new WorkerThreadContext)
310 { 329 {
330 DCHECK(isMainThread());
311 MutexLocker lock(threadSetMutex()); 331 MutexLocker lock(threadSetMutex());
312 workerThreads().add(this); 332 workerThreads().add(this);
313 } 333 }
314 334
315 std::unique_ptr<CrossThreadClosure> WorkerThread::createWorkerThreadTask(std::un ique_ptr<ExecutionContextTask> task, bool isInstrumented) 335 std::unique_ptr<CrossThreadClosure> WorkerThread::createWorkerThreadTask(std::un ique_ptr<ExecutionContextTask> task, bool isInstrumented)
316 { 336 {
317 if (isInstrumented) 337 if (isInstrumented)
318 isInstrumented = !task->taskNameForInstrumentation().isEmpty(); 338 isInstrumented = !task->taskNameForInstrumentation().isEmpty();
319 if (isInstrumented) { 339 if (isInstrumented) {
320 DCHECK(isCurrentThread()); 340 DCHECK(isCurrentThread());
(...skipping 26 matching lines...) Expand all
347 m_exitCode = ExitCode::SyncForciblyTerminated; 367 m_exitCode = ExitCode::SyncForciblyTerminated;
348 } 368 }
349 return; 369 return;
350 } 370 }
351 m_terminated = true; 371 m_terminated = true;
352 372
353 // Signal the thread to notify that the thread's stopping. 373 // Signal the thread to notify that the thread's stopping.
354 if (m_terminationEvent) 374 if (m_terminationEvent)
355 m_terminationEvent->signal(); 375 m_terminationEvent->signal();
356 376
377 m_workerThreadContext->notifyContextDestroyed();
378
357 // If the worker thread was never initialized, don't start another 379 // If the worker thread was never initialized, don't start another
358 // shutdown, but still wait for the thread to signal when shutdown has 380 // shutdown, but still wait for the thread to signal when shutdown has
359 // completed on initializeOnWorkerThread(). 381 // completed on initializeOnWorkerThread().
360 if (!m_workerGlobalScope) { 382 if (!m_workerGlobalScope) {
361 DCHECK_EQ(ExitCode::NotTerminated, m_exitCode); 383 DCHECK_EQ(ExitCode::NotTerminated, m_exitCode);
362 m_exitCode = ExitCode::GracefullyTerminated; 384 m_exitCode = ExitCode::GracefullyTerminated;
363 return; 385 return;
364 } 386 }
365 387
366 // Determine if we should synchronously terminate or schedule to terminate 388 // Determine if we should synchronously terminate or schedule to terminate
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
587 (*task)(); 609 (*task)();
588 } 610 }
589 611
590 WorkerThread::ExitCode WorkerThread::getExitCode() 612 WorkerThread::ExitCode WorkerThread::getExitCode()
591 { 613 {
592 MutexLocker lock(m_threadStateMutex); 614 MutexLocker lock(m_threadStateMutex);
593 return m_exitCode; 615 return m_exitCode;
594 } 616 }
595 617
596 } // namespace blink 618 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698