Chromium Code Reviews| 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 040ce92ea79208362ca3f48cfceb67291d092614..1d400490bf6e991094c6e735012ce0a86638f432 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" |
| @@ -29,10 +30,15 @@ WorkerBackingThread::WorkerBackingThread(WebThread* thread, bool shouldCallGCOnS |
| , m_isOwningThread(false) |
| , m_shouldCallGCOnShutdown(shouldCallGCOnShutdown) |
| { |
| + // WorkerBackingThread is created on main but needs to be initialized on the |
| + // thread in order to attach that thread. |
| + thread->getWebTaskRunner()->postTask(BLINK_FROM_HERE, threadSafeBind(&WorkerBackingThread::initialize, AllowCrossThreadAccess(this))); |
|
haraken
2016/05/11 00:18:31
I still don't understand why you have to call init
flackr
2016/05/18 05:26:50
I've changed WorkerBackingThread so that when you
|
| } |
| WorkerBackingThread::~WorkerBackingThread() |
| { |
| + if (!m_isOwningThread) |
| + signalShutdownAndWait(); |
|
haraken
2016/05/11 00:18:31
I'd move this to CompositorWorkerThread::clearShar
flackr
2016/05/18 05:26:50
Done.
|
| #if DCHECK_IS_ON() |
| MutexLocker locker(m_mutex); |
| DCHECK_EQ(0u, m_workerScriptCount); |
| @@ -46,7 +52,8 @@ void WorkerBackingThread::attach() |
| if (++m_workerScriptCount > 1) |
| return; |
| } |
| - initialize(); |
| + if (m_isOwningThread) |
| + initialize(); |
| } |
| void WorkerBackingThread::detach() |
| @@ -56,7 +63,8 @@ void WorkerBackingThread::detach() |
| if (--m_workerScriptCount > 0) |
| return; |
| } |
| - shutdown(); |
| + if (m_isOwningThread) |
| + shutdown(); |
| } |
| void WorkerBackingThread::initialize() |
| @@ -75,7 +83,7 @@ void WorkerBackingThread::initialize() |
| Platform::current()->didStartWorkerThread(); |
| } |
| -void WorkerBackingThread::shutdown() |
| +void WorkerBackingThread::shutdown(WaitableEvent* doneEvent) |
| { |
| if (m_isOwningThread) |
| Platform::current()->willStopWorkerThread(); |
| @@ -90,6 +98,15 @@ void WorkerBackingThread::shutdown() |
| V8PerIsolateData::destroy(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(); |
| } |
| } // namespace blink |