summaryrefslogtreecommitdiff
path: root/libs/gui/BLASTBufferQueue.cpp
diff options
context:
space:
mode:
author Vishnu Nair <vishnun@google.com> 2021-10-04 22:03:18 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2021-10-04 22:03:18 +0000
commit0363ad304fb6ab82724ac7766a067708501c8f34 (patch)
tree87a87a67e6b1dc7f34b99c900eda7b976ac45e72 /libs/gui/BLASTBufferQueue.cpp
parent95720276538db4b9e2ab7af2c47ad6960ea2fe31 (diff)
parent51e4dc89f0e9b93f0be3204181caa9bef5376746 (diff)
Merge "BlastBufferQueue: Fix async worker deadlock" into sc-v2-dev
Diffstat (limited to 'libs/gui/BLASTBufferQueue.cpp')
-rw-r--r--libs/gui/BLASTBufferQueue.cpp18
1 files changed, 15 insertions, 3 deletions
diff --git a/libs/gui/BLASTBufferQueue.cpp b/libs/gui/BLASTBufferQueue.cpp
index 9f52487857..e8e664bd76 100644
--- a/libs/gui/BLASTBufferQueue.cpp
+++ b/libs/gui/BLASTBufferQueue.cpp
@@ -736,14 +736,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); }