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

Commit 43c450e5 authored by Shai Barack's avatar Shai Barack
Browse files

Add Message#clear()

Code that needs to clear a Message (such as after it's been removed) but has no interest in
recycling Messages should be able to just call this.

Flag: build.RELEASE_PACKAGE_MESSAGEQUEUE_IMPLEMENTATION

Change-Id: I94965662a83c0941a01e86b3344d0a7ee59cb3cb
parent 45d6e93f
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -3047,7 +3047,7 @@ public final class MessageQueue {
                }
                if (removeMatches) {
                    if (p.removeFromStack()) {
                        msg.recycleUnchecked();
                        msg.clear();
                        decAndTraceMessageCount();
                        if (mMessageCounts.incrementCancelled()) {
                            concurrentWake();
@@ -3086,7 +3086,7 @@ public final class MessageQueue {
            if (compare.compareMessage(msg, h, what, object, r, when)) {
                if (removeMatches) {
                    if (queue.remove(msg)) {
                        msg.recycleUnchecked();
                        msg.clear();
                        decAndTraceMessageCount();
                        found = true;
                    }
+17 −12
Original line number Diff line number Diff line
@@ -333,8 +333,23 @@ public final class Message implements Parcelable {
     */
    @UnsupportedAppUsage
    void recycleUnchecked() {
        // Mark the message as in use while it remains in the recycled object pool.
        // Clear out all other details.
        clear();
        if (!MessageQueue.getUseConcurrent()) {
            synchronized (sPoolSync) {
                if (sPoolSize < MAX_POOL_SIZE) {
                    next = sPool;
                    sPool = this;
                    sPoolSize++;
                }
            }
        }
    }

    /**
     * Clears all Message contents.
     */
    void clear() {
        // Prevent accidental reuse such as if this Message is recycled.
        flags = FLAG_IN_USE;
        what = 0;
        arg1 = 0;
@@ -347,16 +362,6 @@ public final class Message implements Parcelable {
        target = null;
        callback = null;
        data = null;

        if (!MessageQueue.getUseConcurrent()) {
            synchronized (sPoolSync) {
                if (sPoolSize < MAX_POOL_SIZE) {
                    next = sPool;
                    sPool = this;
                    sPoolSize++;
                }
            }
        }
    }

    /**