AudioFlinger: Fix lock inversion for timestampCorrectionEnabled

Test: see bug for dynamic lock inversion detection
Bug: 302532421
Bug: 306751935
Merged-In: I31b6c3494ba710fba9ebee42f6570ff9b38fe221
Change-Id: I31b6c3494ba710fba9ebee42f6570ff9b38fe221
diff --git a/services/audioflinger/Threads.cpp b/services/audioflinger/Threads.cpp
index a928ae2..b0df25c 100644
--- a/services/audioflinger/Threads.cpp
+++ b/services/audioflinger/Threads.cpp
@@ -8126,6 +8126,9 @@
     // used to request a deferred sleep, to be executed later while mutex is unlocked
     uint32_t sleepUs = 0;
 
+    // timestamp correction enable is determined under lock, used in processing step.
+    bool timestampCorrectionEnabled = false;
+
     int64_t lastLoopCountRead = -2;  // never matches "previous" loop, when loopCount = 0.
 
     // loop while there is work to do
@@ -8290,6 +8293,7 @@
             }
             sleepUs = 0;
 
+            timestampCorrectionEnabled = isTimestampCorrectionEnabled_l();
             lockEffectChains_l(effectChains);
         }
 
@@ -8446,13 +8450,6 @@
                     && time > mTimestamp.mTimeNs[ExtendedTimestamp::LOCATION_KERNEL]) {
 
                 mTimestampVerifier.add(position, time, mSampleRate);
-
-                // Correct timestamps
-                bool timestampCorrectionEnabled = false;
-                {
-                    audio_utils::lock_guard l(mutex());
-                    timestampCorrectionEnabled = isTimestampCorrectionEnabled_l();
-                }
                 if (timestampCorrectionEnabled) {
                     ALOGVV("TS_BEFORE: %d %lld %lld",
                             id(), (long long)time, (long long)position);