summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTreehugger Robot <treehugger-gerrit@google.com>2022-02-08 03:16:38 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2022-02-08 03:16:38 +0000
commitfbeb4c1ba33b7c6f42de7d065f55c81abdbbaa98 (patch)
treeaf6973fdf5b23a080faef3b6b17960982eb8982f
parent71c24fa16c999d1a5a7b6b94311b70a679f48d1a (diff)
parent01fe9492d06b2b01dc126bb2172910665b6b54e7 (diff)
downloadnative-fbeb4c1ba33b7c6f42de7d065f55c81abdbbaa98.tar.gz
Merge "BlastBufferQueue: Fix async worker deadlock" into android12-gsi
-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 94e1ae1c74..eb803a3966 100644
--- a/libs/gui/BLASTBufferQueue.cpp
+++ b/libs/gui/BLASTBufferQueue.cpp
@@ -738,14 +738,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); }