diff options
| author | 2021-10-04 22:13:41 +0000 | |
|---|---|---|
| committer | 2021-10-04 22:13:41 +0000 | |
| commit | bcb6fb80edb36ebe3653cfda1532d3b5c4706037 (patch) | |
| tree | ef2fab533f6d1fa8a9bd8779e08495ea937be454 /libs/gui/BLASTBufferQueue.cpp | |
| parent | c61cd22104c67ec6629c3eaaa4f1360c51b7c903 (diff) | |
| parent | 0363ad304fb6ab82724ac7766a067708501c8f34 (diff) | |
Merge "BlastBufferQueue: Fix async worker deadlock" into sc-v2-dev am: 0363ad304f
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/native/+/15961340
Change-Id: I0686a922378dfd73702d3e6255b12ef7971659c5
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 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); }  |