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

Commit cf4bd2aa authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Don't add removed messages to the heap" into main

parents b19fdf6a bf4b36c6
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -153,8 +153,11 @@ public final class Message implements Parcelable {
     * The CAS loop shouldn't fail due to FLAG_IN_USE or FLAG_ASYNCHRONOUS being set because those
     * are only changed when a message is initially created and enqueued. However, we loop anyways
     * in case additional flags that can be modified are added in the future.
     *
     * @hide
     */
    boolean markRemoved() {
    @VisibleForTesting
    public boolean markRemoved() {
        int localFlags;
        do {
            localFlags = this.flags;
+3 −3
Original line number Diff line number Diff line
@@ -215,9 +215,9 @@ public final class MessageStack {
            }
            // MessageHeap will maintain its own ordering of Messages, so it doesn't matter that we
            // 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.isRemoved()) {
                getHeap(current).add(current);
            }
            current = current.next;
        }

+13 −0
Original line number Diff line number Diff line
@@ -50,6 +50,19 @@ public final class MessageStackTest {
        assertEquals(10, stack.sizeForTest());
    }

    /**
     * Check that the stack doesn't sweep already-removed messages.
     */
    @Test
    public void testPushRemovedMessage() {
        MessageStack stack = new MessageStack();
        Message m = new Message();
        m.markRemoved();
        stack.pushMessage(m);
        stack.heapSweep();
        assertEquals(0, stack.combinedHeapSizesForTest());
    }

    /**
     * Verify quitting state
     */