summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Jeff Brown <jeffbrown@google.com> 2012-11-01 15:46:10 -0700
committer Android Git Automerger <android-git-automerger@android.com> 2012-11-01 15:46:10 -0700
commitd2592635c179f8eb3a6fa91aa42e23cc469eb83c (patch)
tree93093fb08e488c35f6bc79b6872c7c0563d1393f
parented7a0262694dc87ef3e5f67603caef9c50f72b4c (diff)
parent62831a7bd02868316ad1a16dcf13c98896fdbbdc (diff)
am 62831a7b: Merge "Eliminate potential reentrance from unregisterInputChannel." into jb-mr1-dev
* commit '62831a7bd02868316ad1a16dcf13c98896fdbbdc': Eliminate potential reentrance from unregisterInputChannel.
-rw-r--r--services/input/InputDispatcher.cpp21
-rw-r--r--services/input/InputDispatcher.h1
2 files changed, 16 insertions, 6 deletions
diff --git a/services/input/InputDispatcher.cpp b/services/input/InputDispatcher.cpp
index 7862e172ea90..0465215a8e8c 100644
--- a/services/input/InputDispatcher.cpp
+++ b/services/input/InputDispatcher.cpp
@@ -224,10 +224,16 @@ void InputDispatcher::dispatchOnce() {
AutoMutex _l(mLock);
mDispatcherIsAliveCondition.broadcast();
- dispatchOnceInnerLocked(&nextWakeupTime);
+ // Run a dispatch loop if there are no pending commands.
+ // The dispatch loop might enqueue commands to run afterwards.
+ if (!haveCommandsLocked()) {
+ dispatchOnceInnerLocked(&nextWakeupTime);
+ }
+ // Run all pending commands if there are any.
+ // If any commands were run then force the next poll to wake up immediately.
if (runCommandsLockedInterruptible()) {
- nextWakeupTime = LONG_LONG_MIN; // force next poll to wake up immediately
+ nextWakeupTime = LONG_LONG_MIN;
}
} // release lock
@@ -562,6 +568,10 @@ bool InputDispatcher::isStaleEventLocked(nsecs_t currentTime, EventEntry* entry)
return currentTime - entry->eventTime >= STALE_EVENT_TIMEOUT;
}
+bool InputDispatcher::haveCommandsLocked() const {
+ return !mCommandQueue.isEmpty();
+}
+
bool InputDispatcher::runCommandsLockedInterruptible() {
if (mCommandQueue.isEmpty()) {
return false;
@@ -3247,9 +3257,10 @@ status_t InputDispatcher::registerInputChannel(const sp<InputChannel>& inputChan
}
mLooper->addFd(fd, 0, ALOOPER_EVENT_INPUT, handleReceiveCallback, this);
-
- runCommandsLockedInterruptible();
} // release lock
+
+ // Wake the looper because some connections have changed.
+ mLooper->wake();
return OK;
}
@@ -3294,8 +3305,6 @@ status_t InputDispatcher::unregisterInputChannelLocked(const sp<InputChannel>& i
nsecs_t currentTime = now();
abortBrokenDispatchCycleLocked(currentTime, connection, notify);
- runCommandsLockedInterruptible();
-
connection->status = Connection::STATUS_ZOMBIE;
return OK;
}
diff --git a/services/input/InputDispatcher.h b/services/input/InputDispatcher.h
index 6099c43b3db7..d4f932eb9068 100644
--- a/services/input/InputDispatcher.h
+++ b/services/input/InputDispatcher.h
@@ -899,6 +899,7 @@ private:
KeyEntry* synthesizeKeyRepeatLocked(nsecs_t currentTime);
// Deferred command processing.
+ bool haveCommandsLocked() const;
bool runCommandsLockedInterruptible();
CommandEntry* postCommandLocked(Command command);