From 5cbcb0a39ba07327747ed224706d111c530b7876 Mon Sep 17 00:00:00 2001 From: Bobby Holley Date: Mon, 15 Jun 2015 16:16:19 -0700 Subject: [PATCH] Bug 1174939 - Implement TaskDispatcher::DispatchTasksFor. r=jww --- dom/media/TaskDispatcher.h | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/dom/media/TaskDispatcher.h b/dom/media/TaskDispatcher.h index 6151c64245e1..225d54075654 100644 --- a/dom/media/TaskDispatcher.h +++ b/dom/media/TaskDispatcher.h @@ -56,6 +56,7 @@ public: already_AddRefed 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 group(Move(mTaskGroups[i])); - nsRefPtr thread = group->mThread; - - AbstractThread::DispatchFailureHandling failureHandling = group->mFailureHandling; - AbstractThread::DispatchReason reason = mIsTailDispatcher ? AbstractThread::TailDispatch - : AbstractThread::NormalDispatch; - nsCOMPtr 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 aGroup) + { + nsRefPtr thread = aGroup->mThread; + + AbstractThread::DispatchFailureHandling failureHandling = aGroup->mFailureHandling; + AbstractThread::DispatchReason reason = mIsTailDispatcher ? AbstractThread::TailDispatch + : AbstractThread::NormalDispatch; + nsCOMPtr r = new TaskGroupRunnable(Move(aGroup)); + thread->Dispatch(r.forget(), failureHandling, reason); + } + // Direct tasks. std::queue> mDirectTasks;