src/solaris/native/sun/awt/gtk2_interface.c
Print this page
@@ -79,11 +79,11 @@
const gint SELECTED = 1 << 9;
const gint DEFAULT = 1 << 10;
static void *gtk2_libhandle = NULL;
static void *gthread_libhandle = NULL;
-static gboolean flag_g_thread_get_initialized = FALSE;
+
static jmp_buf j;
/* Widgets */
static GtkWidget *gtk2_widget = NULL;
static GtkWidget *gtk2_window = NULL;
@@ -500,11 +500,11 @@
fp_gtk_file_chooser_get_filenames = dl_symbol(
"gtk_file_chooser_get_filenames");
fp_gtk_g_slist_length = dl_symbol("g_slist_length");
}
-gboolean gtk2_load()
+gboolean gtk2_load(JNIEnv *env)
{
gboolean result;
int i;
int (*handler)();
int (*io_handler)();
@@ -808,20 +808,27 @@
*/
handler = XSetErrorHandler(NULL);
io_handler = XSetIOErrorHandler(NULL);
if (fp_gtk_check_version(2, 2, 0) == NULL) {
- // Init the thread system to use GLib in a thread-safe mode
- if (!flag_g_thread_get_initialized) {
- flag_g_thread_get_initialized = TRUE;
+ jclass class = (*env)->FindClass(env, "sun/misc/GThreadHelper");
+ jmethodID mid_isInitializationNeeded = (*env)->GetStaticMethodID(env, class, "isInitializationNeeded", "()Z");
+ jmethodID mid_lock = (*env)->GetStaticMethodID(env, class, "lock", "()V");
+ jmethodID mid_unlock = (*env)->GetStaticMethodID(env, class, "unlock", "()V");
+ jmethodID mid_initFinished = (*env)->GetStaticMethodID(env, class, "initFinished", "()V");
+ // Init the thread system to use GLib in a thread-safe mode
+ (*env)->CallStaticVoidMethod(env, class, mid_lock);
+ if ((*env)->CallStaticBooleanMethod(env, class, mid_isInitializationNeeded)) {
fp_g_thread_init(NULL);
//According the GTK documentation, gdk_threads_init() should be
//called before gtk_init() or gtk_init_check()
fp_gdk_threads_init();
+ (*env)->CallStaticVoidMethod(env, class, mid_initFinished);
}
+ (*env)->CallStaticVoidMethod(env, class, mid_unlock);
}
result = (*fp_gtk_init_check)(NULL, NULL);
XSetErrorHandler(handler);
XSetIOErrorHandler(io_handler);