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

Commit ba7e4216 authored by Shai Barack's avatar Shai Barack
Browse files

Add CombinedMessageQueue#mNextBarrierToken

CombinedMessageQueue needs to preserve all @UnsupposedAppUsage fields from LegacyMessageQueue.

Bug: 376573804
Change-Id: I214b9fb53f3bdd875fe4a046b5764916ac805b56
Flag: build.RELEASE_PACKAGE_MESSAGEQUEUE_IMPLEMENTATION
parent 8e5e69ab
Loading
Loading
Loading
Loading
+12 −8
Original line number Original line Diff line number Diff line
@@ -85,11 +85,6 @@ public final class MessageQueue {
    // queue for async messages when inserting a message at the tail.
    // queue for async messages when inserting a message at the tail.
    private int mLegacyAsyncMessageCount;
    private int mLegacyAsyncMessageCount;


    // The next barrier token.
    // Barriers are indicated by messages with a null target whose arg1 field carries the token.
    @UnsupportedAppUsage
    private int mLegacyNextBarrierToken;

    /*
    /*
     * Select between two implementations of message queue. The legacy implementation is used
     * Select between two implementations of message queue. The legacy implementation is used
     * by default as it provides maximum compatibility with applications and tests that
     * by default as it provides maximum compatibility with applications and tests that
@@ -900,7 +895,12 @@ public final class MessageQueue {
        // Enqueue a new sync barrier token.
        // Enqueue a new sync barrier token.
        // We don't need to wake the queue because the purpose of a barrier is to stall it.
        // We don't need to wake the queue because the purpose of a barrier is to stall it.
        if (sForceConcurrent) {
        if (sForceConcurrent) {
            final int token = mNextBarrierToken.getAndIncrement();
            final int token = mNextBarrierTokenAtomic.getAndIncrement();

            // b/376573804: apps and tests may expect to be able to use reflection
            // to read this value. Make some effort to support this legacy use case.
            mNextBarrierToken = token + 1;

            final Message msg = Message.obtain();
            final Message msg = Message.obtain();


            msg.markInUse();
            msg.markInUse();
@@ -915,7 +915,7 @@ public final class MessageQueue {
        }
        }


        synchronized (this) {
        synchronized (this) {
            final int token = mLegacyNextBarrierToken++;
            final int token = mNextBarrierToken++;
            final Message msg = Message.obtain();
            final Message msg = Message.obtain();
            msg.markInUse();
            msg.markInUse();
            msg.when = when;
            msg.when = when;
@@ -2292,7 +2292,11 @@ public final class MessageQueue {


    // The next barrier token.
    // The next barrier token.
    // Barriers are indicated by messages with a null target whose arg1 field carries the token.
    // Barriers are indicated by messages with a null target whose arg1 field carries the token.
    private final AtomicInteger mNextBarrierToken = new AtomicInteger(1);
    private final AtomicInteger mNextBarrierTokenAtomic = new AtomicInteger(1);

    // Must retain this for compatibility reasons.
    @UnsupportedAppUsage
    private int mNextBarrierToken;


    /* Protects mNextIsDrainingStack */
    /* Protects mNextIsDrainingStack */
    private final ReentrantLock mDrainingLock = new ReentrantLock();
    private final ReentrantLock mDrainingLock = new ReentrantLock();