Bug 1245789 - Make XPCOMThreadWrapper::GetCurrent() work. r=bholley

XPCOMThreadWrapper::GetCurrent() is failing because it's not keeping
AbstractThread::sCurrentThreadTLS up to date. This causes assertion failures
during startup of the GMP stack when dispatching via InvokeAsync to the GMP
thread, which is an XPCOM thread wrapped by the XPCOMThreadWrapper.

We can trivially initialize AbstractThread::sCurrentThreadTLS to be the
XPCOMThreadWrapper on the target thread, since it's thread-local-storage, and
the target thread won't change.

MozReview-Commit-ID: EIEFZppR2PS
This commit is contained in:
Chris Pearce 2016-04-12 16:12:22 +12:00
Родитель a7ef15b6b8
Коммит 4eaf999528
3 изменённых файлов: 12 добавлений и 5 удалений

Просмотреть файл

@ -357,7 +357,7 @@ GeckoMediaPluginService::GetThread(nsIThread** aThread)
return rv;
}
mAbstractGMPThread = CreateXPCOMAbstractThreadWrapper(mGMPThread, false);
mAbstractGMPThread = AbstractThread::CreateXPCOMThreadWrapper(mGMPThread, false);
// Tell the thread to initialize plugins
InitializePlugins();

Просмотреть файл

@ -146,10 +146,17 @@ AbstractThread::DispatchDirectTask(already_AddRefed<nsIRunnable> aRunnable)
GetCurrent()->TailDispatcher().AddDirectTask(Move(aRunnable));
}
/* static */
already_AddRefed<AbstractThread>
CreateXPCOMAbstractThreadWrapper(nsIThread* aThread, bool aRequireTailDispatch)
AbstractThread::CreateXPCOMThreadWrapper(nsIThread* aThread, bool aRequireTailDispatch)
{
RefPtr<XPCOMThreadWrapper> wrapper = new XPCOMThreadWrapper(aThread, aRequireTailDispatch);
// Set the thread-local sCurrentThreadTLS to point to the wrapper on the
// target thread. This ensures that sCurrentThreadTLS is as expected by
// AbstractThread::GetCurrent() on the target thread.
nsCOMPtr<nsIRunnable> r =
NS_NewRunnableFunction([wrapper]() { sCurrentThreadTLS.set(wrapper); });
aThread->Dispatch(r.forget(), NS_DISPATCH_NORMAL);
return wrapper.forget();
}

Просмотреть файл

@ -42,6 +42,9 @@ public:
AbstractThread(bool aSupportsTailDispatch) : mSupportsTailDispatch(aSupportsTailDispatch) {}
static already_AddRefed<AbstractThread>
CreateXPCOMThreadWrapper(nsIThread* aThread, bool aRequireTailDispatch);
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(AbstractThread);
enum DispatchFailureHandling { AssertDispatchSuccess, DontAssertDispatchSuccess };
@ -92,9 +95,6 @@ protected:
const bool mSupportsTailDispatch;
};
already_AddRefed<AbstractThread> CreateXPCOMAbstractThreadWrapper(nsIThread* aThread,
bool aRequireTailDispatch);
} // namespace mozilla
#endif