bug 1539039 notify WorkletImpl before WorkletThread shutdown on xpcom shutdown r=baku

This gives WorkletImpl a chance to send a message to release worklet thread
objects.

This is used only for PaintWorklet until PaintWorklet uses its own threads.

Differential Revision: https://phabricator.services.mozilla.com/D25353

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Karl Tomlinson 2019-04-01 16:51:18 +00:00
parent d0778fd087
commit d0133206f2
3 changed files with 14 additions and 7 deletions

View File

@ -93,7 +93,7 @@ nsresult WorkletImpl::SendControlMessage(
if (!mWorkletThread) {
// Thread creation. FIXME: this will change.
mWorkletThread = dom::WorkletThread::Create();
mWorkletThread = dom::WorkletThread::Create(this);
if (!mWorkletThread) {
return NS_ERROR_UNEXPECTED;
}

View File

@ -210,10 +210,11 @@ class WorkletThread::TerminateRunnable final : public Runnable {
RefPtr<WorkletThread> mWorkletThread;
};
WorkletThread::WorkletThread()
WorkletThread::WorkletThread(WorkletImpl* aWorkletImpl)
: nsThread(MakeNotNull<ThreadEventQueue<mozilla::EventQueue>*>(
MakeUnique<mozilla::EventQueue>()),
nsThread::NOT_MAIN_THREAD, kWorkletStackSize),
mWorkletImpl(aWorkletImpl),
mExitLoop(false),
mIsTerminating(false) {
MOZ_ASSERT(NS_IsMainThread());
@ -226,8 +227,9 @@ WorkletThread::~WorkletThread() {
}
// static
already_AddRefed<WorkletThread> WorkletThread::Create() {
RefPtr<WorkletThread> thread = new WorkletThread();
already_AddRefed<WorkletThread> WorkletThread::Create(
WorkletImpl* aWorkletImpl) {
RefPtr<WorkletThread> thread = new WorkletThread(aWorkletImpl);
if (NS_WARN_IF(NS_FAILED(thread->Init()))) {
return nullptr;
}
@ -368,7 +370,9 @@ WorkletThread::Observe(nsISupports* aSubject, const char* aTopic,
const char16_t*) {
MOZ_ASSERT(strcmp(aTopic, NS_XPCOM_SHUTDOWN_OBSERVER_ID) == 0);
Terminate();
// The WorkletImpl will terminate the worklet thread after sending a message
// to release worklet thread objects.
mWorkletImpl->NotifyWorkletFinished();
return NS_OK;
}

View File

@ -11,6 +11,7 @@
#include "mozilla/CondVar.h"
#include "mozilla/RefPtr.h"
#include "mozilla/UniquePtr.h"
#include "mozilla/dom/WorkletImpl.h"
#include "nsThread.h"
class nsIRunnable;
@ -23,7 +24,7 @@ class WorkletThread final : public nsThread, public nsIObserver {
NS_DECL_ISUPPORTS_INHERITED
NS_DECL_NSIOBSERVER
static already_AddRefed<WorkletThread> Create();
static already_AddRefed<WorkletThread> Create(WorkletImpl* aWorkletImpl);
// Threads that call EnsureCycleCollectedJSContext must call
// DeleteCycleCollectedJSContext::Get() before terminating. Clients of
@ -40,7 +41,7 @@ class WorkletThread final : public nsThread, public nsIObserver {
void Terminate();
private:
WorkletThread();
explicit WorkletThread(WorkletImpl* aWorkletImpl);
~WorkletThread();
void RunEventLoop();
@ -60,6 +61,8 @@ class WorkletThread final : public nsThread, public nsIObserver {
NS_IMETHOD
DelayedDispatch(already_AddRefed<nsIRunnable>, uint32_t) override;
const RefPtr<WorkletImpl> mWorkletImpl;
bool mExitLoop; // worklet execution thread
bool mIsTerminating; // main thread