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

Commit 3ad49565 authored by Vishnu Nair's avatar Vishnu Nair Committed by Automerger Merge Worker
Browse files

Merge "BlastBufferQueue: Fix async worker deadlock" into sc-v2-dev am: 0363ad30 am: bcb6fb80

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

Change-Id: I5cd0041d05ff157df5ad642057fe35134a00286e
parents 08dec6cf bcb6fb80
Loading
Loading
Loading
Loading
+15 −3
Original line number Diff line number Diff line
@@ -747,14 +747,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); }