diff android/dw.cpp @ 2502:b6319aed3298

Android: Massive thread safety overhaul. Not quite back to fully functional. WebView is having many complaints about not being on the UI thread... better to get this figured out early... All UI calls will be wrapped in a waitOnUiThread() closure. This is our version of Android's runOnUiThread() except it waits for the closure to finish running so we can return results... and also so that our calls will be in the order desired in the application.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Thu, 06 May 2021 09:55:32 +0000
parents 41984ffb5ca2
children 1c2a79313b04
line wrap: on
line diff
--- a/android/dw.cpp	Thu May 06 00:05:32 2021 +0000
+++ b/android/dw.cpp	Thu May 06 09:55:32 2021 +0000
@@ -90,11 +90,7 @@
     static int runcount = 0;
 
     /* Safety check to prevent multiple initializations... */
-#if defined(__arm__) || defined(__aarch64__)
     if(runcount == 0)
-#else
-    if(runcount == 1)
-#endif
     {
         char *arg = strdup(env->GetStringUTFChars((jstring) path, NULL));
 
@@ -110,9 +106,6 @@
 
         /* Launch the new thread to execute dwmain() */
         dw_thread_new((void *) _dw_main_launch, arg, 0);
-
-        /* Wait until dwmain() calls dw_main() then return */
-        dw_event_wait(_dw_main_event, DW_TIMEOUT_INFINITE);
     }
     runcount++;
 }
@@ -467,12 +460,6 @@
  */
 void API dw_main(void)
 {
-    /* Post the event so dwindowsInit() will return...
-     * allowing the app to start handling events.
-     */
-    dw_event_post(_dw_main_event);
-    dw_event_reset(_dw_main_event);
-
     /* We don't actually run a loop here,
      * we launched a new thread to run the loop there.
      * Just wait for dw_main_quit() on the DWMainEvent.
@@ -3178,7 +3165,7 @@
 {
     JNIEnv *env;
 
-    if((env = (JNIEnv *)pthread_getspecific(_dw_env_key)))
+    if(handle && (env = (JNIEnv *)pthread_getspecific(_dw_env_key)))
     {
         // Construct a String
         jstring jstr = env->NewStringUTF(text);