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

Commit 299d6106 authored by Mark Fasheh's avatar Mark Fasheh Committed by Android (Google) Code Review
Browse files

Merge "DeliQueue: store sync barrier state in mWaitState" into main

parents 51f7ddfe d1d0550a
Loading
Loading
Loading
Loading
+27 −23
Original line number Diff line number Diff line
@@ -317,8 +317,8 @@ public final class MessageQueue {
                newWaitState = WaitState.incrementCounter(waitState);
            } else {
                final long TSmillis = WaitState.getTSMillis(waitState);

                if (msg.when < TSmillis) {
                if (msg.when < TSmillis
                        && (!WaitState.hasSyncBarrier(waitState) || msg.isAsynchronous())) {
                    newWaitState = WaitState.initCounter();
                    needWake = true;
                } else {
@@ -416,6 +416,7 @@ public final class MessageQueue {
            */
            Message next = null;

            boolean waitingOnSyncBarrier = false;
            /*
            * If we have a barrier we should return the async node (if it exists and is ready)
            */
@@ -423,6 +424,7 @@ public final class MessageQueue {
                if (asyncMsg != null && (returnEarliest || now >= asyncMsg.when)) {
                    found = asyncMsg;
                } else {
                    waitingOnSyncBarrier = true;
                    next = asyncMsg;
                }
            } else { /* No barrier. */
@@ -513,11 +515,9 @@ public final class MessageQueue {
            /*
             * Try to swap waitstate back from a counter to a deadline. If we can't then that means
             * the counter was incremented and we need to loop back to pick up any new items.
             *
             * TODO: Encode sync barrier state here
             */
            if (!sWaitState.compareAndSet(this, oldWaitState,
                    WaitState.composeDeadline(nextDeadline, false))) {
                    WaitState.composeDeadline(nextDeadline, waitingOnSyncBarrier))) {
                continue;
            }
            if (found != null || nextDeadline != 0) {
@@ -745,16 +745,21 @@ public final class MessageQueue {
                    + " barrier token has not been posted or has already been removed.");
        }

        if (Thread.currentThread() != mLooperThread) {
        boolean needWake;
        while (true) {
            long waitState = mWaitState;
            long newWaitState;

            if (WaitState.isCounter(waitState)) {
                // Thread is already awake and processing messages
                newWaitState = WaitState.incrementCounter(waitState);
                needWake = false;
            } else if (!WaitState.hasSyncBarrier(waitState)) {
                // Thread is asleep but not waiting on sync barrier
                newWaitState = WaitState.incrementDeadline(waitState);
                needWake = false;
            } else {
                // Thread is asleep, wake up
                newWaitState = WaitState.initCounter();
                needWake = true;
            }
@@ -767,7 +772,6 @@ public final class MessageQueue {
            concurrentWake();
        }
    }
    }

    /**
     * Get the timestamp of the next executable message in our priority queue.