diff options
| author | 2021-10-04 22:26:20 +0000 | |
|---|---|---|
| committer | 2021-10-04 22:26:20 +0000 | |
| commit | 3ad49565783f301b73d0f5fec0d741af9ebd9fca (patch) | |
| tree | cb75c3322963e5444366d39c2536920393bb66a7 /libs/gui/BLASTBufferQueue.cpp | |
| parent | 08dec6cfd6dcc25cd2452e62b4b0a57fb9de60ce (diff) | |
| parent | bcb6fb80edb36ebe3653cfda1532d3b5c4706037 (diff) | |
Merge "BlastBufferQueue: Fix async worker deadlock" into sc-v2-dev am: 0363ad304f am: bcb6fb80ed
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/native/+/15961340
Change-Id: I5cd0041d05ff157df5ad642057fe35134a00286e
Diffstat (limited to 'libs/gui/BLASTBufferQueue.cpp')
| -rw-r--r-- | libs/gui/BLASTBufferQueue.cpp | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/libs/gui/BLASTBufferQueue.cpp b/libs/gui/BLASTBufferQueue.cpp index 14ec9486ad..2b17616eda 100644 --- a/libs/gui/BLASTBufferQueue.cpp +++ b/libs/gui/BLASTBufferQueue.cpp @@ -747,14 +747,26 @@ private: std::unique_lock<std::mutex> lock(mMutex); while (!mDone) { while (!mRunnables.empty()) { - std::function<void()> runnable = mRunnables.front(); - mRunnables.pop_front(); - runnable(); + std::deque<std::function<void()>> runnables = std::move(mRunnables); + mRunnables.clear(); + lock.unlock(); + // Run outside the lock since the runnable might trigger another + // post to the async worker. + execute(runnables); + lock.lock(); } mCv.wait(lock); } } + void execute(std::deque<std::function<void()>>& runnables) { + while (!runnables.empty()) { + std::function<void()> runnable = runnables.front(); + runnables.pop_front(); + runnable(); + } + } + public: AsyncWorker() : Singleton<AsyncWorker>() { mThread = std::thread(&AsyncWorker::run, this); } |