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..5e8e3914ddcffe06ae1b8ddec3443c7527dd866f 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,13 @@ WorkerBackingThread::WorkerBackingThread(WebThread* thread, bool shouldCallGCOnS |
| , m_isOwningThread(false) |
| , m_shouldCallGCOnShutdown(shouldCallGCOnShutdown) |
| { |
| + thread->getWebTaskRunner()->postTask(BLINK_FROM_HERE, threadSafeBind(&WorkerBackingThread::initialize, AllowCrossThreadAccess(this))); |
|
haraken
2016/05/09 02:00:53
Would you elaborate on why you need to post a task
flackr
2016/05/10 18:07:39
Added a comment - we create WorkerBackingThread on
|
| } |
| WorkerBackingThread::~WorkerBackingThread() |
| { |
| + if (!m_isOwningThread) |
| + signalShutdownAndWait(); |
|
haraken
2016/05/09 02:00:53
Would you help me understand why you need to call
flackr
2016/05/10 18:07:39
Similar to initialization, the shutdown must be do
|
| #if DCHECK_IS_ON() |
| MutexLocker locker(m_mutex); |
| DCHECK_EQ(0u, m_workerScriptCount); |
| @@ -46,7 +50,8 @@ void WorkerBackingThread::attach() |
| if (++m_workerScriptCount > 1) |
| return; |
| } |
| - initialize(); |
| + if (m_isOwningThread) |
| + initialize(); |
| } |
| void WorkerBackingThread::detach() |
| @@ -56,7 +61,8 @@ void WorkerBackingThread::detach() |
| if (--m_workerScriptCount > 0) |
| return; |
| } |
| - shutdown(); |
| + if (m_isOwningThread) |
| + shutdown(); |
| } |
| void WorkerBackingThread::initialize() |
| @@ -75,7 +81,7 @@ void WorkerBackingThread::initialize() |
| Platform::current()->didStartWorkerThread(); |
| } |
| -void WorkerBackingThread::shutdown() |
| +void WorkerBackingThread::shutdown(WaitableEvent* doneEvent) |
| { |
| if (m_isOwningThread) |
| Platform::current()->willStopWorkerThread(); |
| @@ -90,6 +96,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 |