Bug 1768581 - Part 12: Swap the order of MaybeFastShutdown and KillClearOnShutdown inside AdvanceShutdownPhase and add extra NS_ProcessPendingEvents for the main thread. r=xpcom-reviewers,nika

This change will effectively anticipate the fast shutdown by half a phase, making it more coherent with the phase it is defined to happen.

Depends on D160250

Differential Revision: https://phabricator.services.mozilla.com/D160628
This commit is contained in:
Jens Stutte 2022-11-19 10:15:32 +00:00
Родитель 18f605d9a6
Коммит d8100b452d
2 изменённых файлов: 19 добавлений и 17 удалений

Просмотреть файл

@ -13580,7 +13580,7 @@
#ifdef MOZ_CODE_COVERAGE
value: 0
#else
value: 3
value: 2
#endif
mirror: always

Просмотреть файл

@ -350,14 +350,14 @@ void AppShutdown::AdvanceShutdownPhaseInternal(
nsCOMPtr<nsIThread> thread = do_GetCurrentThread();
if (sCurrentShutdownPhase >= ShutdownPhase::AppShutdownConfirmed) {
// Give runnables dispatched so far as part of the ongoing phase a chance
// to run before actually advancing the phase. We can do this only after
// we passed the point of no return and thus can expect a linear flow
// through our shutdown phases. This way the processing is also covered
// by the terminator's timer.
// Note that this happens only for main thread runnables, such that the
// correct way of ensuring shutdown processing remains to have an async
// shutdown blocker.
// Give runnables dispatched between two calls to AdvanceShutdownPhase
// a chance to run before actually advancing the phase. We must do this
// only after we passed the point of no return and thus can expect a linear
// flow through our shutdown phases. This way the processing is also
// covered by the terminator's timer of the previous phase.
// Note that this affects only main thread runnables, such that the correct
// way of ensuring shutdown processing remains to have an async shutdown
// blocker.
if (thread) {
NS_ProcessPendingEvents(thread);
}
@ -366,22 +366,24 @@ void AppShutdown::AdvanceShutdownPhaseInternal(
// From now on any IsInOrBeyond checks will find the new phase set.
sCurrentShutdownPhase = aPhase;
// TODO: Bug 1768581
// We think it would be more logical to have the following order here:
// AppShutdown::MaybeFastShutdown(aPhase);
// sTerminator->AdvancePhase(aPhase);
// obsService->NotifyObservers(...);
// mozilla::KillClearOnShutdown(aPhase);
#ifndef ANDROID
if (sTerminator) {
sTerminator->AdvancePhase(aPhase);
}
#endif
AppShutdown::MaybeFastShutdown(aPhase);
// This will null out the gathered pointers for this phase synchronously.
// Note that we keep the old order here to avoid breakage, so be aware that
// the notifications fired below will find these already cleared in case
// you expected the opposite.
mozilla::KillClearOnShutdown(aPhase);
AppShutdown::MaybeFastShutdown(aPhase);
// Empty our MT event queue to process any side effects thereof.
if (thread) {
NS_ProcessPendingEvents(thread);
}
if (doNotify) {
const char* aTopic = AppShutdown::GetObserverKey(aPhase);