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))); |
} |
WorkerBackingThread::~WorkerBackingThread() |
{ |
+ if (!m_isOwningThread) |
+ signalShutdownAndWait(); |
#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() |
haraken
2016/05/06 02:45:51
+yhirano: Would you review the changes to the shut
|
+{ |
+ WaitableEvent doneEvent; |
+ m_backingThread->platformThread().getWebTaskRunner()->postTask(BLINK_FROM_HERE, threadSafeBind(&WorkerBackingThread::shutdown, AllowCrossThreadAccess(this), AllowCrossThreadAccess(&doneEvent))); |
+ doneEvent.wait(); |
} |
} // namespace blink |