Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2df7c451 authored by Robert Carr's avatar Robert Carr
Browse files

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
parent 6451714a
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -206,12 +206,14 @@ int64_t TransactionCompletedListener::getNextIdLocked() {
}

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;
    }