Bug 1637500 - P3. Have GetCurrentSerialEventTarget return running XPCOMThreadWrapper. r=froydnj

This will allow to remove AbstractThread::Current() as GetCurrentSerialEventTarget TLS value will be set whenever a task dispatched on the XPCOMThreadWrapper is run.

Differential Revision: https://phabricator.services.mozilla.com/D80355
This commit is contained in:
Jean-Yves Avenard 2020-06-23 05:05:38 +00:00
parent 87438519f0
commit 05a0f10af0
2 changed files with 16 additions and 0 deletions

View File

@ -96,4 +96,19 @@ TEST(TaskQueue, GetCurrentSerialEventTarget)
tq1->AwaitShutdownAndIdle();
}
TEST(AbstractThread, GetCurrentSerialEventTarget)
{
RefPtr<AbstractThread> mainThread = AbstractThread::GetCurrent();
EXPECT_EQ(mainThread, AbstractThread::MainThread());
Unused << mainThread->Dispatch(NS_NewRunnableFunction(
"TestAbstractThread::TestCurrentSerialEventTarget::TestBody",
[mainThread]() {
nsCOMPtr<nsISerialEventTarget> thread = GetCurrentSerialEventTarget();
EXPECT_EQ(thread, mainThread);
}));
// Spin the event loop.
NS_ProcessPendingEvents(nullptr);
}
} // namespace TestTaskQueue

View File

@ -190,6 +190,7 @@ class XPCOMThreadWrapper final : public AbstractThread,
NS_IMETHOD Run() override {
MOZ_ASSERT(mThread == AbstractThread::GetCurrent());
MOZ_ASSERT(mThread->IsCurrentThreadIn());
SerialEventTargetGuard guard(mThread);
return mRunnable->Run();
}