From 2df7c451a58238bad1d0221af94a2fcb29dd4970 Mon Sep 17 00:00:00 2001 From: Robert Carr Date: Mon, 4 Apr 2022 12:21:37 -0700 Subject: TransactionCompletedListener: Mutex for getInstance We have always needed this technically, since otherwise calling getInstance from multiple threads could fail. It seems before we were lucky enough to not actually do that, until the situation in the attached bug arose. Bug: 226882766 Test: Existing tests pass Change-Id: I648f6fa48296599a0c0e0d00a07fb71d9330880d --- libs/gui/SurfaceComposerClient.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'libs/gui/SurfaceComposerClient.cpp') diff --git a/libs/gui/SurfaceComposerClient.cpp b/libs/gui/SurfaceComposerClient.cpp index 6c197c457c..88872f8610 100644 --- a/libs/gui/SurfaceComposerClient.cpp +++ b/libs/gui/SurfaceComposerClient.cpp @@ -206,12 +206,14 @@ int64_t TransactionCompletedListener::getNextIdLocked() { } sp TransactionCompletedListener::sInstance = nullptr; +static std::mutex sListenerInstanceMutex; void TransactionCompletedListener::setInstance(const sp& listener) { sInstance = listener; } sp TransactionCompletedListener::getInstance() { + std::lock_guard lock(sListenerInstanceMutex); if (sInstance == nullptr) { sInstance = new TransactionCompletedListener; } -- cgit v1.2.3-59-g8ed1b