summaryrefslogtreecommitdiff
path: root/firmware/target/hosted/android/system-android.c
diff options
context:
space:
mode:
authorThomas Martitz <kugel@rockbox.org>2012-03-22 20:35:57 +0100
committerThomas Martitz <kugel@rockbox.org>2012-03-22 20:44:52 +0100
commit58e097d4a6c64bf762a8c30e24f16cc62c574519 (patch)
tree16f8135f9ced2e8cd815ff68024b6ef3f237e388 /firmware/target/hosted/android/system-android.c
parentb0df3233917c51049a380f04b909f061de828972 (diff)
downloadrockbox-58e097d4a6c64bf762a8c30e24f16cc62c574519.tar.gz
rockbox-58e097d4a6c64bf762a8c30e24f16cc62c574519.zip
android: Add facility for java code to wait native code to be ready.
Especially when unzipping rockbox.zip, the native code can be initialized a lot later than the java code. The java code needs to be prevented from accessing rockbox structures (e.g. current_tick, event queues) before they're ready. This commit adds wait_rockbox_ready() and fixes dodgy behavior of starting rockbox via widget play button, headset remote buttons or multimedia keys. Also fixes wrong small list items before first redraw. Change-Id: I1caf925e829a9c1c6bb6e0016d5c80574574c91e
Diffstat (limited to 'firmware/target/hosted/android/system-android.c')
-rw-r--r--firmware/target/hosted/android/system-android.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/firmware/target/hosted/android/system-android.c b/firmware/target/hosted/android/system-android.c
index b3c4cdccb5..614d89bfd1 100644
--- a/firmware/target/hosted/android/system-android.c
+++ b/firmware/target/hosted/android/system-android.c
@@ -22,6 +22,7 @@
22 22
23#include <setjmp.h> 23#include <setjmp.h>
24#include <jni.h> 24#include <jni.h>
25#include <pthread.h>
25#include "config.h" 26#include "config.h"
26#include "system.h" 27#include "system.h"
27 28
@@ -95,3 +96,40 @@ Java_org_rockbox_RockboxService_main(JNIEnv *env, jobject this)
95 /* simply return here. this will allow the VM to clean up objects and do 96 /* simply return here. this will allow the VM to clean up objects and do
96 * garbage collection */ 97 * garbage collection */
97} 98}
99
100
101/* below is the facility for external (from other java threads) to safely call
102 * into our snative code. When extracting rockbox.zip the main function is
103 * called only after extraction. This delay can be accounted for by calling
104 * wait_rockbox_ready(). This does not return until the critical parts of Rockbox
105 * can be considered up and running. */
106static pthread_cond_t btn_cond = PTHREAD_COND_INITIALIZER;
107static pthread_mutex_t btn_mtx = PTHREAD_MUTEX_INITIALIZER;
108static bool initialized;
109
110bool is_rockbox_ready(void)
111{
112 /* don't bother with mutexes for this */
113 return initialized;
114}
115
116void wait_rockbox_ready(void)
117{
118 pthread_mutex_lock(&btn_mtx);
119
120 if (!initialized)
121 pthread_cond_wait(&btn_cond, &btn_mtx);
122
123 pthread_mutex_unlock(&btn_mtx);
124}
125
126void set_rockbox_ready(void)
127{
128 pthread_mutex_lock(&btn_mtx);
129
130 initialized = true;
131 /* now ready. signal all waiters */
132 pthread_cond_broadcast(&btn_cond);
133
134 pthread_mutex_unlock(&btn_mtx);
135}