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

Commit 82795fc3 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Execute DelayedCallback outside CallbackScheduler lock"

parents 9897b728 2a550ee0
Loading
Loading
Loading
Loading
+5 −2
Original line number Diff line number Diff line
@@ -71,14 +71,17 @@ void CallbackScheduler::schedule(std::function<void()> callback, std::chrono::mi

void CallbackScheduler::loop() {
    while (true) {
        std::lock_guard<std::mutex> lock(mMutex);
        std::unique_lock<std::mutex> lock(mMutex);
        if (mFinished) {
            // Destructor was called, so let the callback thread die.
            break;
        }
        while (!mQueue.empty() && mQueue.top().isExpired()) {
            mQueue.top().run();
            DelayedCallback callback = mQueue.top();
            mQueue.pop();
            lock.unlock();
            callback.run();
            lock.lock();
        }
        if (mQueue.empty()) {
            // Wait until a new callback is scheduled.