Terminate and wait the worker thread in ~WebEmbeddedWorkerImpl()

It is possible that termination of worker thread is not triggered by the
time of WebEmbeddedWorkerImpl destruction. We should call
WorkerThread::stop() before waiting for the termination of worker thread.

BUG=426332

Review URL: https://codereview.chromium.org/704063002

git-svn-id: svn://svn.chromium.org/blink/trunk@184900 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 8c5eef13
......@@ -416,6 +416,12 @@ void WorkerThread::stopInShutdownSequence()
stopInternal();
}
void WorkerThread::terminateAndWait()
{
stop();
m_terminationEvent->wait();
}
bool WorkerThread::terminated()
{
MutexLocker lock(m_threadCreationMutex);
......
......@@ -69,6 +69,7 @@ public:
WebWaitableEvent* shutdownEvent() { return m_shutdownEvent.get(); }
WebWaitableEvent* terminationEvent() { return m_terminationEvent.get(); }
void terminateAndWait();
static void terminateAndWaitForAllWorkers();
bool isCurrentThread() const;
......
......@@ -51,7 +51,6 @@
#include "platform/network/ContentSecurityPolicyParsers.h"
#include "public/platform/Platform.h"
#include "public/platform/WebURLRequest.h"
#include "public/platform/WebWaitableEvent.h"
#include "public/web/WebDevToolsAgent.h"
#include "public/web/WebServiceWorkerContextClient.h"
#include "public/web/WebServiceWorkerNetworkProvider.h"
......@@ -172,10 +171,8 @@ WebEmbeddedWorkerImpl::WebEmbeddedWorkerImpl(
WebEmbeddedWorkerImpl::~WebEmbeddedWorkerImpl()
{
if (m_workerThread) {
ASSERT(m_workerThread->terminated());
m_workerThread->terminationEvent()->wait();
}
if (m_workerThread)
m_workerThread->terminateAndWait();
ASSERT(runningWorkerInstances().contains(this));
runningWorkerInstances().remove(this);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment