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:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user