summaryrefslogtreecommitdiff
path: root/services/input/EventHub.cpp
diff options
context:
space:
mode:
author Jeff Brown <jeffbrown@google.com> 2011-03-17 20:16:42 -0700
committer Android (Google) Code Review <android-gerrit@google.com> 2011-03-17 20:16:42 -0700
commit6ed6f6d82d7b9f8d82f3ab3a9f718a0e59ffa476 (patch)
tree4376f402d02d4fea5371ccebb11d78e44171af2b /services/input/EventHub.cpp
parent315f19be8ef26fee77db2455f8c2997680755f6d (diff)
parentaa3855d5836d2a2d83baafdf6e40caf90d3dad1c (diff)
Merge "Refactor how timeouts are calculated."
Diffstat (limited to 'services/input/EventHub.cpp')
-rw-r--r--services/input/EventHub.cpp13
1 files changed, 10 insertions, 3 deletions
diff --git a/services/input/EventHub.cpp b/services/input/EventHub.cpp
index 853dda42e030..41993fd2c21a 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);