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

Commit dd091bbb authored by Charles Munger's avatar Charles Munger
Browse files

Consolidate heap selection

Flag: build.RELEASE_PACKAGE_MESSAGEQUEUE_IMPLEMENTATION
Change-Id: Ic586b4bb003b88e24c4071774168c26e502c9411
parent 7aa6729b
Loading
Loading
Loading
Loading
+12 −12
Original line number Diff line number Diff line
@@ -185,6 +185,14 @@ public final class MessageStack {
        return false;
    }

    private MessageHeap getHeap(boolean async) {
        return async ? mAsyncHeap : mSyncHeap;
    }

    private MessageHeap getHeap(Message m) {
        return getHeap(m.isAsynchronous());
    }

    /**
     * Adds not-yet-processed messages into the MessageHeap and creates backlinks.
     */
@@ -209,11 +217,7 @@ public final class MessageStack {
            // insert these Messages in a different order than submitted to the stack.
            // TODO: Removed messages shouldn't be added to the heap, and possibly not into the
            // stack either.
            if (current.isAsynchronous()) {
                mAsyncHeap.add(current);
            } else {
                mSyncHeap.add(current);
            }
            getHeap(current).add(current);
            current = current.next;
        }

@@ -241,7 +245,7 @@ public final class MessageStack {
     * polled message was removed.
     */
    public Message pop(boolean async) {
        final Message m = async ? mAsyncHeap.poll() : mSyncHeap.poll();
        final Message m = getHeap(async).poll();
        if (m != null) {
            // We CAS this so that a remover doesn't attempt to add it to the freelist. If this CAS
            // fails, it has already been removed, and links will be cleared in a drainFreelist()
@@ -269,11 +273,7 @@ public final class MessageStack {
        // An out of range heapIndex means that we've already removed this message from the heap, or
        // it was never added to the heap in the first place.
        if (m.heapIndex >= 0) {
            if (m.isAsynchronous()) {
                mAsyncHeap.removeMessage(m);
            } else {
                mSyncHeap.removeMessage(m);
            }
            getHeap(m).removeMessage(m);
        }
    }

@@ -327,7 +327,7 @@ public final class MessageStack {
     * removed messages.
     */
    public @Nullable Message peek(boolean async) {
        MessageHeap heap = async ? mAsyncHeap : mSyncHeap;
        MessageHeap heap = getHeap(async);
        while (true) {
            final Message m = heap.peek();
            if (m == null) {