From 567533eca188e287f82d99956c5d6a134b9cf8c7 Mon Sep 17 00:00:00 2001 From: Wonsik Kim Date: Tue, 4 May 2021 19:31:29 -0700 Subject: 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 --- libs/gui/BLASTBufferQueue.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'libs/gui/BLASTBufferQueue.cpp') diff --git a/libs/gui/BLASTBufferQueue.cpp b/libs/gui/BLASTBufferQueue.cpp index 3d854c2b92..37fb8448ee 100644 --- a/libs/gui/BLASTBufferQueue.cpp +++ b/libs/gui/BLASTBufferQueue.cpp @@ -666,12 +666,12 @@ private: void run() { std::unique_lock lock(mMutex); while (!mDone) { - mCv.wait(lock); while (!mRunnables.empty()) { std::function runnable = mRunnables.front(); mRunnables.pop_front(); runnable(); } + mCv.wait(lock); } } -- cgit v1.2.3-59-g8ed1b