diff options
author | Koushik Dutta <koushd@gmail.com> | 2012-08-17 00:38:01 -0700 |
---|---|---|
committer | Koushik Dutta <koushd@gmail.com> | 2012-08-17 11:04:47 -0700 |
commit | f45f10705f282a482872d9c1e134c99044e54b3c (patch) | |
tree | b78f9caf9fb921bb9f9ad16506675d5219d0ad3c /ui.c | |
parent | 80da17ec432d433362763df1a775e7b62c5c795a (diff) | |
download | bootable_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.c | 32 |
1 files changed, 24 insertions, 8 deletions
@@ -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; } |