Bug 1982199 - Improve ScheduleWantsLaterTimer error handling. a=RyanVM DONTBUILD
Normally we expect timer creation/initialization to be infallible, but there appear to be rare cases where it fails. It would be good to understand the cause, but first of all we should honor the return value in case of error. Note that allocations during timer init are infallible since bug 1961386, so most likely the cause is not running low on memory. Original Revision: https://phabricator.services.mozilla.com/D262593 Differential Revision: https://phabricator.services.mozilla.com/D266578
This commit is contained in:
committed by
rvandermeulen@mozilla.com
parent
c6927dad6d
commit
ee7cd3cc14
@@ -888,6 +888,7 @@ void ScheduleWantsLaterTimer(uint32_t aWantsLaterDelay) {
|
|||||||
sIdleMemoryCleanupRunner->Cancel();
|
sIdleMemoryCleanupRunner->Cancel();
|
||||||
sIdleMemoryCleanupRunner = nullptr;
|
sIdleMemoryCleanupRunner = nullptr;
|
||||||
}
|
}
|
||||||
|
nsresult timerInitOK = NS_OK;
|
||||||
if (!sIdleMemoryCleanupWantsLater) {
|
if (!sIdleMemoryCleanupWantsLater) {
|
||||||
auto res = NS_NewTimerWithFuncCallback(
|
auto res = NS_NewTimerWithFuncCallback(
|
||||||
CheckIdleMemoryCleanupNeeded, (void*)"IdleMemoryCleanupWantsLaterCheck",
|
CheckIdleMemoryCleanupNeeded, (void*)"IdleMemoryCleanupWantsLaterCheck",
|
||||||
@@ -895,17 +896,28 @@ void ScheduleWantsLaterTimer(uint32_t aWantsLaterDelay) {
|
|||||||
"IdleMemoryCleanupWantsLaterCheck");
|
"IdleMemoryCleanupWantsLaterCheck");
|
||||||
if (res.isOk()) {
|
if (res.isOk()) {
|
||||||
sIdleMemoryCleanupWantsLater = res.unwrap().forget();
|
sIdleMemoryCleanupWantsLater = res.unwrap().forget();
|
||||||
|
} else {
|
||||||
|
timerInitOK = res.unwrapErr();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (sIdleMemoryCleanupWantsLaterScheduled) {
|
if (sIdleMemoryCleanupWantsLaterScheduled) {
|
||||||
sIdleMemoryCleanupWantsLater->Cancel();
|
sIdleMemoryCleanupWantsLater->Cancel();
|
||||||
}
|
}
|
||||||
sIdleMemoryCleanupWantsLater->InitWithNamedFuncCallback(
|
timerInitOK = sIdleMemoryCleanupWantsLater->InitWithNamedFuncCallback(
|
||||||
CheckIdleMemoryCleanupNeeded, (void*)"IdleMemoryCleanupWantsLaterCheck",
|
CheckIdleMemoryCleanupNeeded, (void*)"IdleMemoryCleanupWantsLaterCheck",
|
||||||
aWantsLaterDelay, nsITimer::TYPE_ONE_SHOT_LOW_PRIORITY,
|
aWantsLaterDelay, nsITimer::TYPE_ONE_SHOT_LOW_PRIORITY,
|
||||||
"IdleMemoryCleanupWantsLaterCheck");
|
"IdleMemoryCleanupWantsLaterCheck");
|
||||||
}
|
}
|
||||||
sIdleMemoryCleanupWantsLaterScheduled = true;
|
if (NS_SUCCEEDED(timerInitOK)) {
|
||||||
|
sIdleMemoryCleanupWantsLaterScheduled = true;
|
||||||
|
} else {
|
||||||
|
// Under normal conditions, we would never expect this to fail.
|
||||||
|
MOZ_ASSERT_UNREACHABLE("ScheduleWantsLaterTimer could not create the timer.");
|
||||||
|
// If we were not able to create/init the timer, we will retry the next
|
||||||
|
// time the main thread is about to fall idle. But if we were to stay
|
||||||
|
// idle, we would never purge without this emergency purge.
|
||||||
|
jemalloc_free_dirty_pages();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScheduleIdleMemoryCleanup(uint32_t aWantsLaterDelay) {
|
void ScheduleIdleMemoryCleanup(uint32_t aWantsLaterDelay) {
|
||||||
|
|||||||
Reference in New Issue
Block a user