Skip to content

Commit 1adee11

Browse files
author
Jeff Brown
committed
Optimize dispatcher for back-to-back finished signals.
Minor tweak to the dispatcher to handle as many finished signals in a receive callback as possible instead of going back to the Looper and waiting for the next poll() to hit the callback again. This is part of a series of changes to improve input system pipelining. Bug: 5963420 Change-Id: I8471107371693e21ce8ce7cca1e8d79ba4ca2351
1 parent d1c48a0 commit 1adee11

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

services/input/InputDispatcher.cpp

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2043,18 +2043,30 @@ int InputDispatcher::handleReceiveCallback(int fd, int events, void* data) {
20432043
return 1;
20442044
}
20452045

2046-
bool handled = false;
2047-
status_t status = connection->inputPublisher.receiveFinishedSignal(&handled);
2048-
if (!status) {
2049-
nsecs_t currentTime = now();
2046+
nsecs_t currentTime = now();
2047+
bool gotOne = false;
2048+
status_t status;
2049+
for (;;) {
2050+
bool handled = false;
2051+
status = connection->inputPublisher.receiveFinishedSignal(&handled);
2052+
if (status) {
2053+
break;
2054+
}
20502055
d->finishDispatchCycleLocked(currentTime, connection, handled);
2056+
gotOne = true;
2057+
}
2058+
if (gotOne) {
20512059
d->runCommandsLockedInterruptible();
2052-
return 1;
2060+
if (status == WOULD_BLOCK) {
2061+
return 1;
2062+
}
20532063
}
20542064

2055-
ALOGE("channel '%s' ~ Failed to receive finished signal. status=%d",
2056-
connection->getInputChannelName(), status);
2057-
notify = true;
2065+
notify = status != DEAD_OBJECT || !connection->monitor;
2066+
if (notify) {
2067+
ALOGE("channel '%s' ~ Failed to receive finished signal. status=%d",
2068+
connection->getInputChannelName(), status);
2069+
}
20582070
} else {
20592071
// Monitor channels are never explicitly unregistered.
20602072
// We do it automatically when the remote endpoint is closed so don't warn

0 commit comments

Comments
 (0)