| Index: third_party/WebKit/Source/core/workers/WorkerBackingThread.cpp
|
| diff --git a/third_party/WebKit/Source/core/workers/WorkerBackingThread.cpp b/third_party/WebKit/Source/core/workers/WorkerBackingThread.cpp
|
| index 7267083c7053962b89296c7c05e654b6b6691cce..31dfb0e58b85fb4a6471517bc8892b99f0ebd28b 100644
|
| --- a/third_party/WebKit/Source/core/workers/WorkerBackingThread.cpp
|
| +++ b/third_party/WebKit/Source/core/workers/WorkerBackingThread.cpp
|
| @@ -11,6 +11,7 @@
|
| #include "bindings/core/v8/V8PerIsolateData.h"
|
| #include "platform/RuntimeEnabledFeatures.h"
|
| #include "platform/ThreadSafeFunctional.h"
|
| +#include "platform/WaitableEvent.h"
|
| #include "platform/WebThreadSupportingGC.h"
|
| #include "public/platform/Platform.h"
|
| #include "public/platform/WebTraceLocation.h"
|
| @@ -57,10 +58,13 @@ WorkerBackingThread::WorkerBackingThread(WebThread* thread, bool shouldCallGCOnS
|
| , m_isOwningThread(false)
|
| , m_shouldCallGCOnShutdown(shouldCallGCOnShutdown)
|
| {
|
| + thread->getWebTaskRunner()->postTask(BLINK_FROM_HERE, threadSafeBind(&WorkerBackingThread::initialize, AllowCrossThreadAccess(this)));
|
| }
|
|
|
| WorkerBackingThread::~WorkerBackingThread()
|
| {
|
| + if (!m_isOwningThread)
|
| + signalShutdownAndWait();
|
| #if DCHECK_IS_ON()
|
| MutexLocker locker(m_mutex);
|
| DCHECK_EQ(0u, m_workerScriptCount);
|
| @@ -74,7 +78,8 @@ void WorkerBackingThread::attach()
|
| if (++m_workerScriptCount > 1)
|
| return;
|
| }
|
| - initialize();
|
| + if (m_isOwningThread)
|
| + initialize();
|
| }
|
|
|
| void WorkerBackingThread::detach()
|
| @@ -84,7 +89,8 @@ void WorkerBackingThread::detach()
|
| if (--m_workerScriptCount > 0)
|
| return;
|
| }
|
| - shutdown();
|
| + if (m_isOwningThread)
|
| + shutdown();
|
| }
|
|
|
| void WorkerBackingThread::initialize()
|
| @@ -104,7 +110,7 @@ void WorkerBackingThread::initialize()
|
| Platform::current()->didStartWorkerThread();
|
| }
|
|
|
| -void WorkerBackingThread::shutdown()
|
| +void WorkerBackingThread::shutdown(WaitableEvent* doneEvent)
|
| {
|
| if (m_isOwningThread)
|
| Platform::current()->willStopWorkerThread();
|
| @@ -120,6 +126,15 @@ void WorkerBackingThread::shutdown()
|
| V8PerIsolateData::destroy(m_isolate);
|
| removeWorkerIsolate(m_isolate);
|
| m_isolate = nullptr;
|
| + if (doneEvent)
|
| + doneEvent->signal();
|
| +}
|
| +
|
| +void WorkerBackingThread::signalShutdownAndWait()
|
| +{
|
| + WaitableEvent doneEvent;
|
| + m_backingThread->platformThread().getWebTaskRunner()->postTask(BLINK_FROM_HERE, threadSafeBind(&WorkerBackingThread::shutdown, AllowCrossThreadAccess(this), AllowCrossThreadAccess(&doneEvent)));
|
| + doneEvent.wait();
|
| }
|
|
|
| // static
|
|
|