diff --git a/libs/hwui/hwui/AnimatedImageThread.cpp b/libs/hwui/hwui/AnimatedImageThread.cpp index c8990039875e2..3d5841d308fb7 100644 --- a/libs/hwui/hwui/AnimatedImageThread.cpp +++ b/libs/hwui/hwui/AnimatedImageThread.cpp @@ -22,13 +22,16 @@ namespace android { namespace uirenderer { AnimatedImageThread& AnimatedImageThread::getInstance() { - static AnimatedImageThread* sInstance = new AnimatedImageThread(); - return *sInstance; + [[clang::no_destroy]] static sp sInstance = []() { + sp thread = sp::make(); + thread->start("AnimatedImageThread"); + return thread; + }(); + return *sInstance.get(); } AnimatedImageThread::AnimatedImageThread() { setpriority(PRIO_PROCESS, 0, PRIORITY_NORMAL + PRIORITY_MORE_FAVORABLE); - start("AnimatedImageThread"); } std::future AnimatedImageThread::decodeNextFrame( diff --git a/libs/hwui/hwui/AnimatedImageThread.h b/libs/hwui/hwui/AnimatedImageThread.h index 9e3537430d5aa..fac80e5310e8b 100644 --- a/libs/hwui/hwui/AnimatedImageThread.h +++ b/libs/hwui/hwui/AnimatedImageThread.h @@ -37,6 +37,7 @@ public: std::future reset(const sk_sp&); private: + friend sp; AnimatedImageThread(); };