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

Commit 99343bae authored by Marissa Wall's avatar Marissa Wall
Browse files

blast: protect destruction of callback thread

Wrap the creation and destruction of TransactionCompletedThread's
mThread in a mutex. This will prevent the race condition between
the creation of mThread and mThread.join().

Test: libsurfaceflinger_unittest
      Transaction_test

Change-Id: Ic448872cd5418ce7885b8c2e52a7f1bf02afd772
parent 5aec6412
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
@@ -30,6 +30,8 @@
namespace android {

TransactionCompletedThread::~TransactionCompletedThread() {
    std::lock_guard lockThread(mThreadMutex);

    {
        std::lock_guard lock(mMutex);
        mKeepRunning = false;
@@ -50,11 +52,13 @@ TransactionCompletedThread::~TransactionCompletedThread() {

void TransactionCompletedThread::run() {
    std::lock_guard lock(mMutex);
    if (mRunning) {
    if (mRunning || !mKeepRunning) {
        return;
    }
    mDeathRecipient = new ThreadDeathRecipient();
    mRunning = true;

    std::lock_guard lockThread(mThreadMutex);
    mThread = std::thread(&TransactionCompletedThread::threadMain, this);
}

+4 −1
Original line number Diff line number Diff line
@@ -90,7 +90,10 @@ private:
        }
    };

    std::thread mThread;
    // Protects the creation and destruction of mThread
    std::mutex mThreadMutex;

    std::thread mThread GUARDED_BY(mThreadMutex);

    std::mutex mMutex;
    std::condition_variable_any mConditionVariable;