diff options
Diffstat (limited to 'firmware/target/hosted/android/system-android.c')
-rw-r--r-- | firmware/target/hosted/android/system-android.c | 38 |
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. */ | ||
106 | static pthread_cond_t btn_cond = PTHREAD_COND_INITIALIZER; | ||
107 | static pthread_mutex_t btn_mtx = PTHREAD_MUTEX_INITIALIZER; | ||
108 | static bool initialized; | ||
109 | |||
110 | bool is_rockbox_ready(void) | ||
111 | { | ||
112 | /* don't bother with mutexes for this */ | ||
113 | return initialized; | ||
114 | } | ||
115 | |||
116 | void 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 | |||
126 | void 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 | } | ||