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

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

Merge "Revert^3 "Don't call nativePollOnce unnecessarily"" into main

parents fc5684bb 8fcfc1bb
Loading
Loading
Loading
Loading
+6 −26
Original line number Diff line number Diff line
@@ -98,7 +98,6 @@ public final class MessageQueue {
    @UnsupportedAppUsage
    private final ArrayList<IdleHandler> mIdleHandlers = new ArrayList<IdleHandler>();
    private SparseArray<FileDescriptorRecord> mFileDescriptorRecords;
    private volatile boolean mHasFileDescriptorRecords;
    private IdleHandler[] mPendingIdleHandlers;
    private boolean mQuitting;

@@ -585,17 +584,6 @@ public final class MessageQueue {

            setFileDescriptorEvents(fdNum, 0);
        }

        // Indicate to maybePollOnce() if we have file descriptor records that
        // need to be polled for events.
        // We write this volatile field here and read it from the worker thread.
        // Adding an FD on a client thread and polling for events on the worker thread are
        // inherently racy. If the worker thread skips polling because it thinks there are
        // no FDs to watch and there is a Message to handle, then the worker will still
        // poll for the same events the next time. Events won't be missed, they'll just be
        // interleaved with Message handling in undefined ways.
        mHasFileDescriptorRecords = mFileDescriptorRecords != null
                && (mFileDescriptorRecords.size() > 0);
    }

    // Called from native code.
@@ -865,18 +853,9 @@ public final class MessageQueue {
        }
    }

    private void maybePollOnce(int nextPollTimeoutMillis) {
        if (!Flags.messageQueueNativePollOnceAndForAll()) {
            // If nativePollOnce optimization is not in effect, poll unconditionally.
            nativePollOnce(mPtr, nextPollTimeoutMillis);
        } else if (nextPollTimeoutMillis != 0 || mHasFileDescriptorRecords || getQuitting()) {
            // We need to wait for the next message, or we need to poll for file descriptor events.
            nativePollOnce(mPtr, nextPollTimeoutMillis);
        }
    }

    private Message nextConcurrent() {
        if (mPtr == 0) {
        final long ptr = mPtr;
        if (ptr == 0) {
            return null;
        }

@@ -888,7 +867,7 @@ public final class MessageQueue {
            }

            mMessageDirectlyQueued = false;
            maybePollOnce(mNextPollTimeoutMillis);
            nativePollOnce(ptr, mNextPollTimeoutMillis);

            Message msg = nextMessage(false, false);
            if (msg != null) {
@@ -955,7 +934,8 @@ public final class MessageQueue {
        // Return here if the message loop has already quit and been disposed.
        // This can happen if the application tries to restart a looper after quit
        // which is not supported.
        if (mPtr == 0) {
        final long ptr = mPtr;
        if (ptr == 0) {
            return null;
        }

@@ -966,7 +946,7 @@ public final class MessageQueue {
                Binder.flushPendingCommands();
            }

            maybePollOnce(nextPollTimeoutMillis);
            nativePollOnce(ptr, nextPollTimeoutMillis);

            synchronized (this) {
                // Try to retrieve the next message.  Return if found.
+1 −23
Original line number Diff line number Diff line
@@ -438,7 +438,6 @@ public final class MessageQueue {
    private final Object mFileDescriptorRecordsLock = new Object();
    @GuardedBy("mFileDescriptorRecordsLock")
    private SparseArray<FileDescriptorRecord> mFileDescriptorRecords;
    private volatile boolean mHasFileDescriptorRecords;

    // The next barrier token.
    // Barriers are indicated by messages with a null target whose arg1 field carries the token.
@@ -886,16 +885,6 @@ public final class MessageQueue {
        }
    }

    private void maybePollOnce(int nextPollTimeoutMillis) {
        if (!Flags.messageQueueNativePollOnceAndForAll()) {
            // If nativePollOnce optimization is not in effect, poll unconditionally.
            nativePollOnce(mPtr, nextPollTimeoutMillis);
        } else if (nextPollTimeoutMillis != 0 || mHasFileDescriptorRecords || getQuitting()) {
            // We need to wait for the next message, or we need to poll for file descriptor events.
            nativePollOnce(mPtr, nextPollTimeoutMillis);
        }
    }

    Message next() {
        final long ptr = mPtr;
        if (ptr == 0) {
@@ -910,7 +899,7 @@ public final class MessageQueue {
            }

            mMessageDirectlyQueued = false;
            maybePollOnce(mNextPollTimeoutMillis);
            nativePollOnce(ptr, mNextPollTimeoutMillis);

            Message msg = nextMessage(false, false);
            if (msg != null) {
@@ -1761,17 +1750,6 @@ public final class MessageQueue {
            mFileDescriptorRecords.removeAt(index);
            setFileDescriptorEvents(fdNum, 0);
        }

        // Indicate to maybePollOnce() if we have file descriptor records that
        // need to be polled for events.
        // We write this volatile field here and read it from the worker thread.
        // Adding an FD on a client thread and polling for events on the worker thread are
        // inherently racy. If the worker thread skips polling because it thinks there are
        // no FDs to watch and there is a Message to handle, then the worker will still
        // poll for the same events the next time. Events won't be missed, they'll just be
        // interleaved with Message handling in undefined ways.
        mHasFileDescriptorRecords = mFileDescriptorRecords != null
                && (mFileDescriptorRecords.size() > 0);
    }

    // Called from native code.
+1 −23
Original line number Diff line number Diff line
@@ -71,7 +71,6 @@ public final class MessageQueue {
    @UnsupportedAppUsage
    private final ArrayList<IdleHandler> mIdleHandlers = new ArrayList<IdleHandler>();
    private SparseArray<FileDescriptorRecord> mFileDescriptorRecords;
    private volatile boolean mHasFileDescriptorRecords;
    private IdleHandler[] mPendingIdleHandlers;
    private boolean mQuitting;

@@ -327,17 +326,6 @@ public final class MessageQueue {
            mFileDescriptorRecords.removeAt(index);
            nativeSetFileDescriptorEvents(mPtr, fdNum, 0);
        }

        // Indicate to maybePollOnce() if we have file descriptor records that
        // need to be polled for events.
        // We write this volatile field here and read it from the worker thread.
        // Adding an FD on a client thread and polling for events on the worker thread are
        // inherently racy. If the worker thread skips polling because it thinks there are
        // no FDs to watch and there is a Message to handle, then the worker will still
        // poll for the same events the next time. Events won't be missed, they'll just be
        // interleaved with Message handling in undefined ways.
        mHasFileDescriptorRecords = mFileDescriptorRecords != null
                && (mFileDescriptorRecords.size() > 0);
    }

    // Called from native code.
@@ -392,16 +380,6 @@ public final class MessageQueue {

    private static final AtomicLong mMessagesDelivered = new AtomicLong();

    private void maybePollOnce(int nextPollTimeoutMillis) {
        if (!Flags.messageQueueNativePollOnceAndForAll()) {
            // If nativePollOnce optimization is not in effect, poll unconditionally.
            nativePollOnce(mPtr, nextPollTimeoutMillis);
        } else if (nextPollTimeoutMillis != 0 || mHasFileDescriptorRecords) {
            // We need to wait for the next message, or we need to poll for file descriptor events.
            nativePollOnce(mPtr, nextPollTimeoutMillis);
        }
    }

    @UnsupportedAppUsage
    Message next() {
        // Return here if the message loop has already quit and been disposed.
@@ -419,7 +397,7 @@ public final class MessageQueue {
                Binder.flushPendingCommands();
            }

            maybePollOnce(nextPollTimeoutMillis);
            nativePollOnce(ptr, nextPollTimeoutMillis);

            synchronized (this) {
                // Try to retrieve the next message.  Return if found.
+0 −8
Original line number Diff line number Diff line
@@ -317,14 +317,6 @@ flag {
    is_exported: true
}

flag {
    name: "message_queue_native_poll_once_and_for_all"
    namespace: "system_performance"
    description: "Don't call nativePollOnce unnecessarily."
    bug: "410218466"
    is_fixed_read_only: false
}

flag {
     name: "message_queue_testability"
     namespace: "system_performance"