summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTreehugger Robot <treehugger-gerrit@google.com>2022-02-07 17:44:55 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2022-02-07 17:44:55 +0000
commit09fe4d2cc07beb8f776a6967fe3ae69d248c5fb1 (patch)
treea8ad372f6afdb29e803d8b5759150163373b4b22
parent32ac30f71c2fdec2ae8058e75fee8ca7c86db8cf (diff)
parent19cd146ac0f8b13c811ef476a48ece9d9b87e285 (diff)
downloadnative-09fe4d2cc07beb8f776a6967fe3ae69d248c5fb1.tar.gz
Merge "BlastBufferQueue: Fix async worker deadlock"
-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 5b59c592df..9baf79b443 100644
--- a/libs/gui/BLASTBufferQueue.cpp
+++ b/libs/gui/BLASTBufferQueue.cpp
@@ -731,14 +731,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); }