summaryrefslogtreecommitdiff
path: root/libs/gui/BLASTBufferQueue.cpp
diff options
context:
space:
mode:
author Treehugger Robot <treehugger-gerrit@google.com> 2022-02-07 18:15:09 +0000
committer Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> 2022-02-07 18:15:09 +0000
commitd2a1d62d372eb9dac4c67957827e855823229c90 (patch)
tree83c7051868e48e93be9e8bf6201f9cf8e13c11b3 /libs/gui/BLASTBufferQueue.cpp
parent4a4b28fed6e40f2668c3cf444631a85155c3d911 (diff)
parentb40813fb700f455441ff149f9ef7e2e4aaca1e83 (diff)
Merge "BlastBufferQueue: Fix async worker deadlock" am: 09fe4d2cc0 am: b40813fb70
Original change: https://android-review.googlesource.com/c/platform/frameworks/native/+/1973102 Change-Id: I82ad894f57c13dcf006fa053d9b28cd06bd62136
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 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); }