Bug 1592488 - P11. Ensure an AbstractThread exists for each WorkerThread. r=baku

As with P9; in order to be able to use MozPromise and direct task dispatching we need an AbstractThread to exist.

Differential Revision: https://phabricator.services.mozilla.com/D74675
This commit is contained in:
Jean-Yves Avenard 2020-05-13 02:00:57 +00:00
parent dde81db3d7
commit 4738ae3ddd
2 changed files with 19 additions and 0 deletions

View File

@ -93,6 +93,8 @@ already_AddRefed<WorkerThread> WorkerThread::Create(
NS_WARNING("Failed to create new thread!");
return nullptr;
}
thread->mAbstractThread = AbstractThread::CreateXPCOMThreadWrapper(
thread, false /* aRequireTailDispatch */);
return thread.forget();
}
@ -330,6 +332,14 @@ PerformanceCounter* WorkerThread::GetPerformanceCounter(
return nullptr;
}
NS_IMETHODIMP
WorkerThread::Shutdown() {
MOZ_ALWAYS_SUCCEEDS(nsThread::Shutdown());
// We need to break the cycle.
mAbstractThread = nullptr;
return NS_OK;
}
NS_IMPL_ISUPPORTS(WorkerThread::Observer, nsIThreadObserver)
NS_IMETHODIMP

View File

@ -17,6 +17,7 @@
class nsIRunnable;
namespace mozilla {
class AbstractThread;
namespace dom {
class WorkerRunnable;
@ -55,6 +56,12 @@ class WorkerThread final : public nsThread {
// Protected by nsThread::mLock and waited on with mWorkerPrivateCondVar.
uint32_t mOtherThreadsDispatchingViaEventTarget;
// We create an AbstractThread for this current nsThread instance in order to
// support direct task dispatching. Direct tasks work in a similar fashion to
// microtasks and allow an IPDL MozPromise to behave like JS promise.
// An AbstractThread only need to exist on the current thread for Direct Task
// dispatch to be available.
RefPtr<AbstractThread> mAbstractThread;
#ifdef DEBUG
// Protected by nsThread::mLock.
bool mAcceptingNonWorkerRunnables;
@ -77,6 +84,8 @@ class WorkerThread final : public nsThread {
PerformanceCounter* GetPerformanceCounter(nsIRunnable* aEvent) const override;
NS_IMETHODIMP Shutdown() override;
NS_INLINE_DECL_REFCOUNTING_INHERITED(WorkerThread, nsThread)
private: