From a942af8a8f7774de0f090525d90c97ba50f3cc0e Mon Sep 17 00:00:00 2001 From: Adrian Salido Date: Thu, 17 Feb 2022 19:22:31 -0800 Subject: SF: fix deadlock while switching resolution Trying to grab mStateLock during kernelTimerChanged could lead to deadlock when changing resolution as display gets recreated and the idle timer may get stopped/re-started. The deadlock could happen when calling OneShotTimer::stop() (due to thread join) in main thread while kernelTimerChanged is waiting for lock. Bug: 222755257 Test: cmd display set-user-preferred-display-mode Change-Id: I0ccc7bccdcee98722c1dced09032ab3953d851cb --- services/surfaceflinger/SurfaceFlinger.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'services/surfaceflinger/SurfaceFlinger.cpp') diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp index e8034de52c..350d7096aa 100644 --- a/services/surfaceflinger/SurfaceFlinger.cpp +++ b/services/surfaceflinger/SurfaceFlinger.cpp @@ -6063,7 +6063,6 @@ void SurfaceFlinger::kernelTimerChanged(bool expired) { static bool updateOverlay = property_get_bool("debug.sf.kernel_idle_timer_update_overlay", true); if (!updateOverlay) return; - if (Mutex::Autolock lock(mStateLock); !isRefreshRateOverlayEnabled()) return; // Update the overlay on the main thread to avoid race conditions with // mRefreshRateConfigs->getCurrentRefreshRate() @@ -6073,6 +6072,7 @@ void SurfaceFlinger::kernelTimerChanged(bool expired) { ALOGW("%s: default display is null", __func__); return; } + if (!display->isRefreshRateOverlayEnabled()) return; const auto desiredActiveMode = display->getDesiredActiveMode(); const std::optional desiredModeId = desiredActiveMode -- cgit v1.2.3-59-g8ed1b