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

Commit 567533ec authored by Wonsik Kim's avatar Wonsik Kim
Browse files

BLASTBufferQueue: fix AsyncWorker race condition

Address the following scenario:

[T1] AsyncProducerListener::onBufferReleased() is called
     for the first time.
[T2] AsyncWorker::mThread is just created and not acquired
     the mutex yet.
[T1] AsyncProducerListener::post() is called and acquired the mutex.
[T1] The runnable is queued to mRunnable and mCv is notified.
     There are no threads waiting for mCv, so this is ignored.
[T2] AsyncWorker::mThread acquires the mutex, and wait on mCv.

If the client is waiting for the first onBufferReleased callback,
it will be stuck indefinitely.

Bug: 186630119
Test: atest --iterations 100 android.media.cts.MediaSyncTest
Change-Id: I65d98d64233fa8d488788319a4850be4cace48cc
parent 316bdbd6
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -666,12 +666,12 @@ private:
    void run() {
        std::unique_lock<std::mutex> lock(mMutex);
        while (!mDone) {
            mCv.wait(lock);
            while (!mRunnables.empty()) {
                std::function<void()> runnable = mRunnables.front();
                mRunnables.pop_front();
                runnable();
            }
            mCv.wait(lock);
        }
    }