sensor: don't block Read more than 30 secs

Don't block on Read forever, force timeout if nothing happens for
a while. 30 secs is high enough not to be the desired delay for
the movement sensors.

Change-Id: I257120809855382d7a945a132f5b7a2cff1ecfca
Reviewed-on: https://go-review.googlesource.com/8580
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
This commit is contained in:
Burcu Dogan 2015-04-07 16:32:17 -04:00
parent dad00d93e6
commit 16015b6039
1 changed files with 2 additions and 3 deletions

View File

@ -43,10 +43,9 @@ int android_readQueue(int looperId, ASensorEventQueue* q, int n, int32_t* types,
int id;
int events;
ASensorEvent event;
// TODO(jbd): Timeout if pollAll blocks longer than it should.
int i = 0;
// Block forever until new events are on the queue.
while (i < n && (id = ALooper_pollAll(-1, NULL, &events, NULL)) >= 0) {
// Block for 30 secs, timeout if nothing happens.
while (i < n && (id = ALooper_pollAll(30*1000, NULL, &events, NULL)) >= 0) {
if (id != looperId) {
continue;
}