From 0220614e37f863970fb77d893bb768d8a51b8eb0 Mon Sep 17 00:00:00 2001 From: Timothy Nikkel Date: Sat, 25 May 2024 09:45:37 +0000 Subject: [PATCH] Bug 1892643. Allow checking for shutdown in the image decode pool after the decode pool has been cleared. r=gfx-reviewers,nical Differential Revision: https://phabricator.services.mozilla.com/D208086 --- image/AnimationSurfaceProvider.cpp | 6 ++---- image/DecodePool.cpp | 9 ++++++++- image/DecodePool.h | 2 +- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/image/AnimationSurfaceProvider.cpp b/image/AnimationSurfaceProvider.cpp index 05208a4d1910..a197d3439a8d 100644 --- a/image/AnimationSurfaceProvider.cpp +++ b/image/AnimationSurfaceProvider.cpp @@ -245,8 +245,7 @@ void AnimationSurfaceProvider::Run() { // release the thread as soon as possible. The animation may advance even // during shutdown, which keeps us decoding, and thus blocking the decode // pool during teardown. - if (!mDecoder || !continueDecoding || - DecodePool::Singleton()->IsShuttingDown()) { + if (!mDecoder || !continueDecoding || DecodePool::IsShuttingDown()) { return; } @@ -282,8 +281,7 @@ void AnimationSurfaceProvider::Run() { // animation may advance even during shutdown, which keeps us decoding, and // thus blocking the decode pool during teardown. MOZ_ASSERT(result == LexerResult(Yield::OUTPUT_AVAILABLE)); - if (!checkForNewFrameAtYieldResult || - DecodePool::Singleton()->IsShuttingDown()) { + if (!checkForNewFrameAtYieldResult || DecodePool::IsShuttingDown()) { return; } } diff --git a/image/DecodePool.cpp b/image/DecodePool.cpp index b63322691452..1f571cf38f9c 100644 --- a/image/DecodePool.cpp +++ b/image/DecodePool.cpp @@ -16,6 +16,7 @@ #include "mozilla/StaticPrefs_image.h" #include "mozilla/TaskController.h" #include "mozilla/TimeStamp.h" +#include "mozilla/AppShutdown.h" #include "nsCOMPtr.h" #include "nsIObserverService.h" #include "nsThreadManager.h" @@ -132,7 +133,13 @@ DecodePool::Observe(nsISupports*, const char* aTopic, const char16_t*) { return NS_OK; } -bool DecodePool::IsShuttingDown() const { return mShuttingDown; } +/* static */ bool DecodePool::IsShuttingDown() { + if (MOZ_UNLIKELY(!sSingleton)) { + return AppShutdown::IsInOrBeyond(ShutdownPhase::XPCOMShutdownThreads); + } + + return sSingleton->mShuttingDown; +} class DecodingTask final : public Task { public: diff --git a/image/DecodePool.h b/image/DecodePool.h index 6b25aadf1740..4cd1dac479e9 100644 --- a/image/DecodePool.h +++ b/image/DecodePool.h @@ -56,7 +56,7 @@ class DecodePool final : public nsIObserver { /// True if the DecodePool is being shutdown. This may only be called by /// threads from the pool to check if they should keep working or not. - bool IsShuttingDown() const; + static bool IsShuttingDown(); /// Ask the DecodePool to run @aTask asynchronously and return immediately. void AsyncRun(IDecodingTask* aTask);