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
diff --git a/libs/gui/SurfaceComposerClient.cpp b/libs/gui/SurfaceComposerClient.cpp
index 6c197c4..88872f8 100644
--- a/libs/gui/SurfaceComposerClient.cpp
+++ b/libs/gui/SurfaceComposerClient.cpp
@@ -206,12 +206,14 @@
}
sp<TransactionCompletedListener> TransactionCompletedListener::sInstance = nullptr;
+static std::mutex sListenerInstanceMutex;
void TransactionCompletedListener::setInstance(const sp<TransactionCompletedListener>& listener) {
sInstance = listener;
}
sp<TransactionCompletedListener> TransactionCompletedListener::getInstance() {
+ std::lock_guard<std::mutex> lock(sListenerInstanceMutex);
if (sInstance == nullptr) {
sInstance = new TransactionCompletedListener;
}