Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b40813fb authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge "BlastBufferQueue: Fix async worker deadlock" am: 09fe4d2c

Original change: https://android-review.googlesource.com/c/platform/frameworks/native/+/1973102

Change-Id: I32ca7a1a993acd299197373e39adce3f7f910733
parents 3fe93b90 09fe4d2c
Loading
Loading
Loading
Loading
+15 −3
Original line number Diff line number Diff line
@@ -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); }