From aa3855d5836d2a2d83baafdf6e40caf90d3dad1c Mon Sep 17 00:00:00 2001 From: Jeff Brown Date: Thu, 17 Mar 2011 01:34:19 -0700 Subject: Refactor how timeouts are calculated. Added a timeout mechanism to EventHub and InputReader so that InputMappers can request timeouts to perform delayed processing of input when needed. Change-Id: Iec2045baaf4e67690b15eef3c09a58d5cac76897 --- services/input/EventHub.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'services/input/EventHub.cpp') diff --git a/services/input/EventHub.cpp b/services/input/EventHub.cpp index e2da7409de46..b90571b4d906 100644 --- a/services/input/EventHub.cpp +++ b/services/input/EventHub.cpp @@ -445,7 +445,7 @@ EventHub::Device* EventHub::getDeviceLocked(int32_t deviceId) const { return NULL; } -bool EventHub::getEvent(RawEvent* outEvent) { +bool EventHub::getEvent(int timeoutMillis, RawEvent* outEvent) { outEvent->deviceId = 0; outEvent->type = 0; outEvent->scanCode = 0; @@ -598,13 +598,20 @@ bool EventHub::getEvent(RawEvent* outEvent) { // when this happens, the EventHub holds onto its own user wake lock while the client // is processing events. Thus the system can only sleep if there are no events // pending or currently being processed. + // + // The timeout is advisory only. If the device is asleep, it will not wake just to + // service the timeout. release_wake_lock(WAKE_LOCK_ID); - int pollResult = poll(mFds.editArray(), mFds.size(), -1); + int pollResult = poll(mFds.editArray(), mFds.size(), timeoutMillis); acquire_wake_lock(PARTIAL_WAKE_LOCK, WAKE_LOCK_ID); - if (pollResult <= 0) { + if (pollResult == 0) { + // Timed out. + return false; + } + if (pollResult < 0) { if (errno != EINTR) { LOGW("poll failed (errno=%d)\n", errno); usleep(100000); -- cgit v1.2.3-59-g8ed1b