Bug 1174939 - Implement TaskDispatcher::DispatchTasksFor. r=jww

This commit is contained in:
Bobby Holley 2015-06-15 16:16:19 -07:00
Родитель bf4e15de86
Коммит 5cbcb0a39b
1 изменённых файлов: 24 добавлений и 8 удалений

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

@ -56,6 +56,7 @@ public:
already_AddRefed<nsIRunnable> aRunnable,
AbstractThread::DispatchFailureHandling aFailureHandling = AbstractThread::AssertDispatchSuccess) = 0;
virtual void DispatchTasksFor(AbstractThread* aThread) = 0;
virtual bool HasTasksFor(AbstractThread* aThread) = 0;
virtual void DrainDirectTasks() = 0;
};
@ -82,14 +83,7 @@ public:
MOZ_ASSERT(mDirectTasks.empty());
for (size_t i = 0; i < mTaskGroups.Length(); ++i) {
UniquePtr<PerThreadTaskGroup> group(Move(mTaskGroups[i]));
nsRefPtr<AbstractThread> thread = group->mThread;
AbstractThread::DispatchFailureHandling failureHandling = group->mFailureHandling;
AbstractThread::DispatchReason reason = mIsTailDispatcher ? AbstractThread::TailDispatch
: AbstractThread::NormalDispatch;
nsCOMPtr<nsIRunnable> r = new TaskGroupRunnable(Move(group));
thread->Dispatch(r.forget(), failureHandling, reason);
DispatchTaskGroup(Move(mTaskGroups[i]));
}
}
@ -132,6 +126,17 @@ public:
return !!GetTaskGroup(aThread) || (aThread == AbstractThread::GetCurrent() && !mDirectTasks.empty());
}
void DispatchTasksFor(AbstractThread* aThread) override
{
for (size_t i = 0; i < mTaskGroups.Length(); ++i) {
if (mTaskGroups[i]->mThread == aThread) {
DispatchTaskGroup(Move(mTaskGroups[i]));
mTaskGroups.RemoveElementAt(i);
return;
}
}
}
private:
struct PerThreadTaskGroup
@ -215,6 +220,17 @@ private:
return nullptr;
}
void DispatchTaskGroup(UniquePtr<PerThreadTaskGroup> aGroup)
{
nsRefPtr<AbstractThread> thread = aGroup->mThread;
AbstractThread::DispatchFailureHandling failureHandling = aGroup->mFailureHandling;
AbstractThread::DispatchReason reason = mIsTailDispatcher ? AbstractThread::TailDispatch
: AbstractThread::NormalDispatch;
nsCOMPtr<nsIRunnable> r = new TaskGroupRunnable(Move(aGroup));
thread->Dispatch(r.forget(), failureHandling, reason);
}
// Direct tasks.
std::queue<nsCOMPtr<nsIRunnable>> mDirectTasks;