aboutsummaryrefslogtreecommitdiffstats
path: root/ui.c
diff options
context:
space:
mode:
authorKoushik Dutta <koushd@gmail.com>2012-08-17 00:38:01 -0700
committerKoushik Dutta <koushd@gmail.com>2012-08-17 11:04:47 -0700
commitf45f10705f282a482872d9c1e134c99044e54b3c (patch)
treeb78f9caf9fb921bb9f9ad16506675d5219d0ad3c /ui.c
parent80da17ec432d433362763df1a775e7b62c5c795a (diff)
downloadbootable_recovery-f45f10705f282a482872d9c1e134c99044e54b3c.zip
bootable_recovery-f45f10705f282a482872d9c1e134c99044e54b3c.tar.gz
bootable_recovery-f45f10705f282a482872d9c1e134c99044e54b3c.tar.bz2
First pass at fixing up the threading issues in ro.cwm.enable_key_repeat.
Change-Id: Id11654b3637ad76a4554ddc3ec62ba546d390400
Diffstat (limited to 'ui.c')
-rw-r--r--ui.c32
1 files changed, 24 insertions, 8 deletions
diff --git a/ui.c b/ui.c
index e500cf7..bd32042 100644
--- a/ui.c
+++ b/ui.c
@@ -901,30 +901,43 @@ int ui_wait_key_with_repeat()
timeout.tv_sec += UI_WAIT_KEY_TIMEOUT_SEC;
int rc = 0;
+ pthread_mutex_lock(&key_queue_mutex);
while (key_queue_len == 0 && rc != ETIMEDOUT) {
- pthread_mutex_lock(&key_queue_mutex);
rc = pthread_cond_timedwait(&key_queue_cond, &key_queue_mutex,
&timeout);
- pthread_mutex_unlock(&key_queue_mutex);
}
- if (rc == ETIMEDOUT && !usb_connected()) return -1;
+ pthread_mutex_unlock(&key_queue_mutex);
+ if (rc == ETIMEDOUT && !usb_connected()) {
+ return key;
+ }
+ pthread_mutex_lock(&key_queue_mutex);
while (key_queue_len > 0) {
unsigned long now_msec;
+ // wtf is this here for?
+ // don't fix threading problems with sleep.
usleep(1);
gettimeofday(&now, NULL);
now_msec = (now.tv_sec * 1000) + (now.tv_usec / 1000);
key = key_queue[0];
-
- pthread_mutex_lock(&key_queue_mutex);
memcpy(&key_queue[0], &key_queue[1], sizeof(int) * --key_queue_len);
- pthread_mutex_unlock(&key_queue_mutex);
+
+ // sanity check the returned key.
+ if (key < 0) {
+ pthread_mutex_unlock(&key_queue_mutex);
+ return key;
+ }
if (!key_pressed[key]) {
- if (key_last_repeat[key] > 0) continue;
- else return key;
+ if (key_last_repeat[key] > 0) {
+ continue;
+ }
+ else {
+ pthread_mutex_unlock(&key_queue_mutex);
+ return key;
+ }
}
int k = 0;
@@ -945,9 +958,12 @@ int ui_wait_key_with_repeat()
continue;
}
}
+ pthread_mutex_unlock(&key_queue_mutex);
return key;
}
+ pthread_mutex_unlock(&key_queue_mutex);
} while (key_queue_len == 0);
+
return key;
}