I had an occasional crasher with the new portableNativeSync impl. Robert
was so kind to point out that the lock object has to be wrapped in a
global JNI reference. Duh. Here it comes now.

2007-04-04  Roman Kennke  <[EMAIL PROTECTED]>

        * native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkToolkit.c
        (init_glib_threads): Create global reference on lock object.

/Roman
-- 
aicas Allerton Interworks Computer Automated Systems GmbH
Haid-und-Neu-Straße 18 * D-76131 Karlsruhe * Germany
http://www.aicas.com   * Tel: +49-721-663 968-0

USt-Id: DE216375633, Handelsregister HRB 109481, AG Karlsruhe
Geschäftsführer: Dr. James J. Hunt
Index: native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkToolkit.c
===================================================================
RCS file: /cvsroot/classpath/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkToolkit.c,v
retrieving revision 1.35
diff -u -1 -5 -r1.35 gnu_java_awt_peer_gtk_GtkToolkit.c
--- native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkToolkit.c	3 Apr 2007 19:33:45 -0000	1.35
+++ native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkToolkit.c	4 Apr 2007 11:29:52 -0000
@@ -101,31 +101,31 @@
 
 JNIEnv *
 cp_gtk_gdk_env()
 {
   union env_union tmp;
   g_assert((*java_vm)->GetEnv(java_vm, &tmp.void_env, JNI_VERSION_1_2) == JNI_OK);
   return tmp.jni_env;
 }
 
 
 GtkWindowGroup *cp_gtk_global_window_group;
 double cp_gtk_dpi_conversion_factor;
 
 static void jni_lock_cb();
 static void jni_unlock_cb();
-static void init_glib_threads(jint, jobject);
+static void init_glib_threads(JNIEnv*, jint, jobject);
 static gboolean post_set_running_flag (gpointer);
 static gboolean set_running_flag (gpointer);
 static gboolean clear_running_flag (gpointer);
 static void init_dpi_conversion_factor (void);
 static void dpi_changed_cb (GtkSettings  *settings,
                             GParamSpec   *pspec);
 
 #if GTK_MINOR_VERSION > 4
 static GLogFunc old_glog_func;
 static void glog_func (const gchar *log_domain,
 		       GLogLevelFlags log_level,
 		       const gchar *message,
 		       gpointer user_data);
 #endif
 
@@ -157,31 +157,31 @@
 
   printCurrentThreadID = (*env)->GetStaticMethodID (env, gtkgenericpeer,
                                                     "printCurrentThread", "()V");
  
   NSA_INIT (env, gtkgenericpeer);
 
   g_assert((*env)->GetJavaVM(env, &java_vm) == 0);
 
   /* GTK requires a program's argc and argv variables, and requires that they
      be valid.  Set it up. */
   argv = (char **) g_malloc (sizeof (char *) * 2);
   argv[0] = (char *) g_malloc(1);
   argv[0][0] = '\0';
   argv[1] = NULL;
   
-  init_glib_threads(portableNativeSync, lock);
+  init_glib_threads(env, portableNativeSync, lock);
 
   /* From GDK 2.0 onwards we have to explicitly call gdk_threads_init */
   gdk_threads_init();
 
   gtk_init (&argc, &argv);
 
 #if SYNCHRONIZE_GDK
   XSynchronize (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), True);
 #endif
 
   gtk_widget_set_default_colormap (gdk_rgb_get_colormap ());
 
   /* Make sure queued calls don't get sent to GTK/GDK while 
      we're shutting down. */
   atexit (gdk_threads_enter);
@@ -244,47 +244,47 @@
 {
 
   JNIEnv * env = cp_gtk_gdk_env();
   if ((*env)->MonitorExit(env, global_lock))
     {
       printf("failure while exiting GTK monitor\n");
     }
 }
 
 /** Initialize GLIB's threads properly, based on the value of the
     gnu.classpath.awt.gtk.portable.native.sync Java system property.  If
     that's unset, use the PORTABLE_NATIVE_SYNC config.h macro.  (TODO: 
     In some release following 0.10, that config.h macro will go away.)
     */ 
 static void 
-init_glib_threads(jint portableNativeSync, jobject lock)
+init_glib_threads(JNIEnv *env, jint portableNativeSync, jobject lock)
 {
   if (portableNativeSync < 0)
     {
 #ifdef PORTABLE_NATIVE_SYNC /* Default value, if not set by the Java system
                                property */ 
       portableNativeSync = 1;
 #else
       portableNativeSync = 0;
 #endif
     }
   
   if (!g_thread_supported ())
     {
       if (portableNativeSync)
         {
-          global_lock = lock;
+          global_lock = (*env)->NewGlobalRef(env, lock);
           gdk_threads_set_lock_functions(&jni_lock_cb, &jni_unlock_cb);
         }
       g_thread_init(NULL);
     }
   else
     {
       /* Warn if portable native sync is desired but the threading
          system is already initialized.  In that case we can't
          override the threading implementation with our portable
          native sync functions. */
       if (portableNativeSync)
         g_printerr ("peer warning: portable native sync disabled.\n");
     }
 
   /* Debugging progress message; uncomment if needed: */

Reply via email to