Bug 1173641 - Hoist shutdown promise resolution into a helper. r=jww

This commit is contained in:
Bobby Holley 2015-06-10 20:06:09 -07:00
parent 99e1dd3dad
commit 888c87b0fd
2 changed files with 12 additions and 5 deletions

View File

@ -167,9 +167,7 @@ MediaTaskQueue::BeginShutdown()
MonitorAutoLock mon(mQueueMonitor);
mIsShutdown = true;
nsRefPtr<ShutdownPromise> p = mShutdownPromise.Ensure(__func__);
if (!mIsRunning) {
mShutdownPromise.Resolve(true, __func__);
}
MaybeResolveShutdown();
mon.NotifyAll();
return p;
}
@ -238,7 +236,7 @@ MediaTaskQueue::Runner::Run()
MOZ_ASSERT(mQueue->mIsRunning);
if (mQueue->mTasks.size() == 0) {
mQueue->mIsRunning = false;
mQueue->mShutdownPromise.ResolveIfExists(true, __func__);
mQueue->MaybeResolveShutdown();
mon.NotifyAll();
return NS_OK;
}
@ -269,7 +267,7 @@ MediaTaskQueue::Runner::Run()
if (mQueue->mTasks.size() == 0) {
// No more events to run. Exit the task runner.
mQueue->mIsRunning = false;
mQueue->mShutdownPromise.ResolveIfExists(true, __func__);
mQueue->MaybeResolveShutdown();
mon.NotifyAll();
return NS_OK;
}
@ -286,6 +284,7 @@ MediaTaskQueue::Runner::Run()
MonitorAutoLock mon(mQueue->mQueueMonitor);
mQueue->mIsRunning = false;
mQueue->mIsShutdown = true;
mQueue->MaybeResolveShutdown();
mon.NotifyAll();
}

View File

@ -94,6 +94,14 @@ protected:
DispatchFailureHandling aFailureHandling,
DispatchReason aReason = NormalDispatch);
void MaybeResolveShutdown()
{
mQueueMonitor.AssertCurrentThreadOwns();
if (mIsShutdown && !mIsRunning) {
mShutdownPromise.ResolveIfExists(true, __func__);
}
}
RefPtr<SharedThreadPool> mPool;
// Monitor that protects the queue and mIsRunning;