Bug 1328643: Add some locking to prevent races caused by Cancel/Init from threads other than the target. r=froydnj

MozReview-Commit-ID: FdAPTGDNKup
This commit is contained in:
Byron Campen [:bwc]
2017-01-11 13:59:19 -06:00
parent 4232eb2f21
commit c6db5a598c
4 changed files with 218 additions and 229 deletions

View File

@@ -287,10 +287,6 @@ nsTimerEvent::Run()
return NS_OK;
}
if (mGeneration != mTimer->GetGeneration()) {
return NS_OK;
}
if (MOZ_LOG_TEST(GetTimerLog(), LogLevel::Debug)) {
TimeStamp now = TimeStamp::Now();
MOZ_LOG(GetTimerLog(), LogLevel::Debug,
@@ -298,7 +294,7 @@ nsTimerEvent::Run()
this, (now - mInitTime).ToMilliseconds()));
}
mTimer->Fire();
mTimer->Fire(mGeneration);
// We call Cancel() to correctly release mTimer.
// Read more in the Cancel() implementation.
@@ -378,7 +374,7 @@ TimerThread::Shutdown()
}
// Need to copy content of mTimers array to a local array
// because call to timers' ReleaseCallback() (and release its self)
// because call to timers' Cancel() (and release its self)
// must not be done under the lock. Destructor of a callback
// might potentially call some code reentering the same lock
// that leads to unexpected behavior or deadlock.
@@ -390,7 +386,7 @@ TimerThread::Shutdown()
uint32_t timersCount = timers.Length();
for (uint32_t i = 0; i < timersCount; i++) {
nsTimerImpl* timer = timers[i];
timer->ReleaseCallback();
timer->Cancel();
ReleaseTimerInternal(timer);
}
@@ -603,7 +599,7 @@ TimerThread::AddTimer(nsTimerImpl* aTimer)
}
nsresult
TimerThread::RemoveTimer(nsTimerImpl* aTimer, bool aDisable)
TimerThread::RemoveTimer(nsTimerImpl* aTimer)
{
MonitorAutoLock lock(mMonitor);
@@ -614,10 +610,6 @@ TimerThread::RemoveTimer(nsTimerImpl* aTimer, bool aDisable)
return NS_ERROR_NOT_AVAILABLE;
}
if (aDisable) {
aTimer->mEventTarget = nullptr;
}
// Awaken the timer thread.
if (mWaiting) {
mNotified = true;