зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1288618 - Part 6: Avoid unnecessarily allocating a TailDispatcher for XPCOMThreadWrapper. r=bholley
This commit is contained in:
Родитель
40fbd338ce
Коммит
9c7f101c32
|
@ -94,6 +94,11 @@ public:
|
||||||
return mTailDispatcher.ref();
|
return mTailDispatcher.ref();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual bool MightHaveTailTasks() override
|
||||||
|
{
|
||||||
|
return mTailDispatcher.isSome();
|
||||||
|
}
|
||||||
|
|
||||||
virtual nsIThread* AsXPCOMThread() override { return mTarget; }
|
virtual nsIThread* AsXPCOMThread() override { return mTarget; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -101,6 +106,23 @@ private:
|
||||||
Maybe<AutoTaskDispatcher> mTailDispatcher;
|
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
|
bool
|
||||||
AbstractThread::RequiresTailDispatch(AbstractThread* aThread) const
|
AbstractThread::RequiresTailDispatch(AbstractThread* aThread) const
|
||||||
{
|
{
|
||||||
|
|
|
@ -66,6 +66,16 @@ public:
|
||||||
// threads which support it.
|
// threads which support it.
|
||||||
virtual TaskDispatcher& TailDispatcher() = 0;
|
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.
|
// Returns true if this supports the tail dispatcher.
|
||||||
bool SupportsTailDispatch() const { return mSupportsTailDispatch; }
|
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
|
// Make sure there are no tasks for this queue waiting in the caller's tail
|
||||||
// dispatcher.
|
// dispatcher.
|
||||||
MOZ_ASSERT_IF(AbstractThread::GetCurrent(),
|
MOZ_ASSERT_IF(AbstractThread::GetCurrent(),
|
||||||
!AbstractThread::GetCurrent()->TailDispatcher().HasTasksFor(this));
|
!AbstractThread::GetCurrent()->HasTailTasksFor(this));
|
||||||
|
|
||||||
mQueueMonitor.AssertCurrentThreadOwns();
|
mQueueMonitor.AssertCurrentThreadOwns();
|
||||||
MOZ_ASSERT(mIsRunning || mTasks.empty());
|
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
|
// Make sure there are no tasks for this queue waiting in the caller's tail
|
||||||
// dispatcher.
|
// dispatcher.
|
||||||
MOZ_ASSERT_IF(AbstractThread::GetCurrent(),
|
MOZ_ASSERT_IF(AbstractThread::GetCurrent(),
|
||||||
!AbstractThread::GetCurrent()->TailDispatcher().HasTasksFor(this));
|
!AbstractThread::GetCurrent()->HasTailTasksFor(this));
|
||||||
|
|
||||||
MonitorAutoLock mon(mQueueMonitor);
|
MonitorAutoLock mon(mQueueMonitor);
|
||||||
while (!mIsShutdown) {
|
while (!mIsShutdown) {
|
||||||
|
@ -169,7 +169,7 @@ TaskQueue::BeginShutdown()
|
||||||
// Dispatch any tasks for this queue waiting in the caller's tail dispatcher,
|
// Dispatch any tasks for this queue waiting in the caller's tail dispatcher,
|
||||||
// since this is the last opportunity to do so.
|
// since this is the last opportunity to do so.
|
||||||
if (AbstractThread* currentThread = AbstractThread::GetCurrent()) {
|
if (AbstractThread* currentThread = AbstractThread::GetCurrent()) {
|
||||||
currentThread->TailDispatcher().DispatchTasksFor(this);
|
currentThread->TailDispatchTasksFor(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
MonitorAutoLock mon(mQueueMonitor);
|
MonitorAutoLock mon(mQueueMonitor);
|
||||||
|
|
Загрузка…
Ссылка в новой задаче