Bug 1052740 - Cancel LazyIdleThread timer before shutting down its thread, r=bsmedberg.

This commit is contained in:
Ben Turner 2014-08-29 11:23:31 -07:00
parent a52fb1dc25
commit 4bbb35972c

View File

@ -229,14 +229,16 @@ LazyIdleThread::ScheduleTimer()
shouldSchedule = !mIdleNotificationCount && !mPendingEventCount;
}
if (NS_FAILED(mIdleTimer->Cancel())) {
NS_WARNING("Failed to cancel timer!");
}
if (mIdleTimer) {
if (NS_FAILED(mIdleTimer->Cancel())) {
NS_WARNING("Failed to cancel timer!");
}
if (shouldSchedule &&
NS_FAILED(mIdleTimer->InitWithCallback(this, mIdleTimeoutMS,
nsITimer::TYPE_ONE_SHOT))) {
NS_WARNING("Failed to schedule timer!");
if (shouldSchedule &&
NS_FAILED(mIdleTimer->InitWithCallback(this, mIdleTimeoutMS,
nsITimer::TYPE_ONE_SHOT))) {
NS_WARNING("Failed to schedule timer!");
}
}
}
@ -252,6 +254,18 @@ LazyIdleThread::ShutdownThread()
nsresult rv;
// Make sure to cancel the shutdown timer before spinning the event loop
// during |mThread->Shutdown()| below. Otherwise the timer might fire and we
// could reenter here.
if (mIdleTimer) {
rv = mIdleTimer->Cancel();
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
mIdleTimer = nullptr;
}
if (mThread) {
if (mShutdownMethod == AutomaticShutdown && NS_IsMainThread()) {
nsCOMPtr<nsIObserverService> obs =
@ -311,15 +325,6 @@ LazyIdleThread::ShutdownThread()
}
}
if (mIdleTimer) {
rv = mIdleTimer->Cancel();
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
mIdleTimer = nullptr;
}
// If our temporary queue has any runnables then we need to dispatch them.
if (queuedRunnables.Length()) {
// If the thread manager has gone away then these runnables will never run.