Bug 1288618 - Part 6: Avoid unnecessarily allocating a TailDispatcher for XPCOMThreadWrapper. r=bholley

--HG--
extra : rebase_source : 38596e6ebfc7eb2fb863e242cee718060abe470c
This commit is contained in:
Matt Woodrow 2016-09-21 15:36:09 +12:00
Родитель 8702620c57
Коммит 4caf5b9aa0
3 изменённых файлов: 35 добавлений и 3 удалений

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

@ -94,6 +94,11 @@ public:
return mTailDispatcher.ref();
}
virtual bool MightHaveTailTasks() override
{
return mTailDispatcher.isSome();
}
virtual nsIThread* AsXPCOMThread() override { return mTarget; }
private:
@ -101,6 +106,23 @@ private:
Maybe<AutoTaskDispatcher> mTailDispatcher;
};
void
AbstractThread::TailDispatchTasksFor(AbstractThread* aThread)
{
if (MightHaveTailTasks()) {
TailDispatcher().DispatchTasksFor(aThread);
}
}
bool
AbstractThread::HasTailTasksFor(AbstractThread* aThread)
{
if (!MightHaveTailTasks()) {
return false;
}
return TailDispatcher().HasTasksFor(aThread);
}
bool
AbstractThread::RequiresTailDispatch(AbstractThread* aThread) const
{

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

@ -66,6 +66,16 @@ public:
// threads which support it.
virtual TaskDispatcher& TailDispatcher() = 0;
// Returns true if we have tail tasks scheduled, or if this isn't known.
// Returns false if we definitely don't have any tail tasks.
virtual bool MightHaveTailTasks() { return true; }
// Helper functions for methods on the tail TasklDispatcher. These check
// HasTailTasks to avoid allocating a TailDispatcher if it isn't
// needed.
void TailDispatchTasksFor(AbstractThread* aThread);
bool HasTailTasksFor(AbstractThread* aThread);
// Returns true if this supports the tail dispatcher.
bool SupportsTailDispatch() const { return mSupportsTailDispatch; }

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

@ -138,7 +138,7 @@ TaskQueue::AwaitIdleLocked()
// Make sure there are no tasks for this queue waiting in the caller's tail
// dispatcher.
MOZ_ASSERT_IF(AbstractThread::GetCurrent(),
!AbstractThread::GetCurrent()->TailDispatcher().HasTasksFor(this));
!AbstractThread::GetCurrent()->HasTailTasksFor(this));
mQueueMonitor.AssertCurrentThreadOwns();
MOZ_ASSERT(mIsRunning || mTasks.empty());
@ -154,7 +154,7 @@ TaskQueue::AwaitShutdownAndIdle()
// Make sure there are no tasks for this queue waiting in the caller's tail
// dispatcher.
MOZ_ASSERT_IF(AbstractThread::GetCurrent(),
!AbstractThread::GetCurrent()->TailDispatcher().HasTasksFor(this));
!AbstractThread::GetCurrent()->HasTailTasksFor(this));
MonitorAutoLock mon(mQueueMonitor);
while (!mIsShutdown) {
@ -169,7 +169,7 @@ TaskQueue::BeginShutdown()
// Dispatch any tasks for this queue waiting in the caller's tail dispatcher,
// since this is the last opportunity to do so.
if (AbstractThread* currentThread = AbstractThread::GetCurrent()) {
currentThread->TailDispatcher().DispatchTasksFor(this);
currentThread->TailDispatchTasksFor(this);
}
MonitorAutoLock mon(mQueueMonitor);