Make mMutex the last attribute to be released
The original attribute declaration order was mTimeKeeper -> mMutex.
This will cause the mMutex be released prior than mTimeKeepr. When
mMutex has been released and mTimeKeeper is still running dispatch(),
the callback can be invoked and try to lock the released mMutex. Please
check the error in https://b.corp.google.com/issues/284388255#comment37.
This CL change the declaration order as mMutex -> mTimekeeper so that
the release order become mTimeKeeper -> mMutex. When releasing
mTimeKeeper, the ~Timer() will join the dispatch thread and thus ensure
the callback won't be invoked after mMutex get released.
Bug: 284388255
Test: Build, flash and run suspend<->resume test for over 96 hours.
Change-Id: I75a3946e641cbe19a0caaeb91433010edcd9c0c7
diff --git a/services/surfaceflinger/Scheduler/VSyncDispatchTimerQueue.h b/services/surfaceflinger/Scheduler/VSyncDispatchTimerQueue.h
index 6499d69..e0fb8f9 100644
--- a/services/surfaceflinger/Scheduler/VSyncDispatchTimerQueue.h
+++ b/services/surfaceflinger/Scheduler/VSyncDispatchTimerQueue.h
@@ -146,13 +146,14 @@
void cancelTimer() REQUIRES(mMutex);
ScheduleResult scheduleLocked(CallbackToken, ScheduleTiming) REQUIRES(mMutex);
+ std::mutex mutable mMutex;
+
static constexpr nsecs_t kInvalidTime = std::numeric_limits<int64_t>::max();
std::unique_ptr<TimeKeeper> const mTimeKeeper;
VsyncSchedule::TrackerPtr mTracker;
nsecs_t const mTimerSlack;
nsecs_t const mMinVsyncDistance;
- std::mutex mutable mMutex;
size_t mCallbackToken GUARDED_BY(mMutex) = 0;
CallbackMap mCallbacks GUARDED_BY(mMutex);