--- sylpheed-0.9.1/src/action.c.alt-thread 2003-05-26 07:58:32 +0400 +++ sylpheed-0.9.1/src/action.c 2003-06-05 19:44:55 +0400 @@ -1116,7 +1116,8 @@ gtk_widget_show(dialog); } -static void catch_status(gpointer data, gint source, GdkInputCondition cond) +static void catch_status_locked(gpointer data, gint source, + GdkInputCondition cond) { ChildInfo *child_info = (ChildInfo *)data; gchar buf; @@ -1134,7 +1135,8 @@ wait_for_children(child_info->children); } -static void catch_input(gpointer data, gint source, GdkInputCondition cond) +static void catch_input_locked(gpointer data, gint source, + GdkInputCondition cond) { Children *children = (Children *)data; ChildInfo *child_info = (ChildInfo *)children->list->data; @@ -1171,7 +1173,8 @@ debug_print("Input to grand child sent.\n"); } -static void catch_output(gpointer data, gint source, GdkInputCondition cond) +static void catch_output_locked(gpointer data, gint source, + GdkInputCondition cond) { ChildInfo *child_info = (ChildInfo *)data; gint c, i; @@ -1214,6 +1217,29 @@ wait_for_children(child_info->children); } +/* Wrappers to ensure proper thread handling */ + +static void catch_status(gpointer data, gint source, GdkInputCondition cond) +{ + gdk_threads_enter(); + catch_status_locked(data, source, cond); + gdk_threads_leave(); +} + +static void catch_input(gpointer data, gint source, GdkInputCondition cond) +{ + gdk_threads_enter(); + catch_input_locked(data, source, cond); + gdk_threads_leave(); +} + +static void catch_output(gpointer data, gint source, GdkInputCondition cond) +{ + gdk_threads_enter(); + catch_output_locked(data, source, cond); + gdk_threads_leave(); +} + static gchar *get_user_string(const gchar *action, ActionType type) { gchar *message; --- sylpheed-0.9.1/src/compose.c.alt-thread 2003-05-20 12:34:28 +0400 +++ sylpheed-0.9.1/src/compose.c 2003-06-05 19:44:55 +0400 @@ -4842,8 +4842,8 @@ return TRUE; } -static void compose_input_cb(gpointer data, gint source, - GdkInputCondition condition) +static void compose_input_cb_locked(gpointer data, gint source, + GdkInputCondition condition) { gchar buf[3]; Compose *compose = (Compose *)data; @@ -4902,6 +4902,14 @@ compose->exteditor_tag = -1; } +static void compose_input_cb(gpointer data, gint source, + GdkInputCondition condition) +{ + gdk_threads_enter(); + compose_input_cb_locked(data, source, condition); + gdk_threads_leave(); +} + static void compose_set_ext_editor_sensitive(Compose *compose, gboolean sensitive) { --- sylpheed-0.9.1/src/gtkstext.c.alt-thread 2002-08-21 08:11:47 +0400 +++ sylpheed-0.9.1/src/gtkstext.c 2003-06-05 19:44:55 +0400 @@ -5696,6 +5696,8 @@ static gint stext_blink_timer_proc (GtkSText *text) { + GDK_THREADS_ENTER (); + if (text->cursor_state_on) { text->cursor_state_on = FALSE; @@ -5717,12 +5719,16 @@ (gpointer) text); } + GDK_THREADS_LEAVE (); + return TRUE; } static gint stext_idle_timer_proc (GtkSText *text) { + GDK_THREADS_ENTER (); + /* make sure the cursor timer is off */ if (text->cursor_timer_id) { @@ -5740,6 +5746,8 @@ gtk_idle_remove (text->cursor_idle_time_timer_id); text->cursor_idle_time_timer_id = 0; + GDK_THREADS_LEAVE (); + return TRUE; } --- sylpheed-0.9.1/src/inc.c.alt-thread 2003-05-23 13:25:15 +0400 +++ sylpheed-0.9.1/src/inc.c 2003-06-05 19:44:55 +0400 @@ -1058,7 +1058,7 @@ } } -static gint inc_autocheck_func(gpointer data) +static gint inc_autocheck_func_locked(gpointer data) { MainWindow *mainwin = (MainWindow *)data; @@ -1072,3 +1072,14 @@ return FALSE; } + +static gint inc_autocheck_func(gpointer data) +{ + gint result; + + gdk_threads_enter(); + result = inc_autocheck_func_locked(data); + gdk_threads_leave(); + + return result; +} --- sylpheed-0.9.1/src/main.c.alt-thread 2003-05-26 10:00:32 +0400 +++ sylpheed-0.9.1/src/main.c 2003-06-05 19:44:55 +0400 @@ -149,6 +149,16 @@ bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); +#if USE_THREADS || USE_LDAP + /* + * Thread support in GLib must be initialized before calling any GLib + * function. + */ + g_thread_init(NULL); + if (!g_thread_supported()) + g_error(_("g_thread is not supported by glib.\n")); +#endif + prog_version = PROG_VERSION; startup_dir = g_get_current_dir(); @@ -167,16 +177,17 @@ gtk_set_locale(); gtk_init(&argc, &argv); + /* + * GTK+ FAQ suggests to call gdk_threads_enter() just before + * gtk_main(). However, it is safer to call it here, just in case we + * enter into some temporary message loop during the initialization. + */ + gdk_threads_enter(); + gdk_rgb_init(); gtk_widget_set_default_colormap(gdk_rgb_get_cmap()); gtk_widget_set_default_visual(gdk_rgb_get_visual()); -#if USE_THREADS || USE_LDAP - g_thread_init(NULL); - if (!g_thread_supported()) - g_error(_("g_thread is not supported by glib.\n")); -#endif - #if HAVE_GDK_IMLIB gdk_imlib_init(); gtk_widget_push_visual(gdk_imlib_get_visual()); @@ -315,6 +326,8 @@ gtk_main(); + gdk_threads_leave(); + return 0; } @@ -557,9 +570,9 @@ return 0; } -static void lock_socket_input_cb(gpointer data, - gint source, - GdkInputCondition condition) +static void lock_socket_input_cb_locked(gpointer data, + gint source, + GdkInputCondition condition) { MainWindow *mainwin = (MainWindow *)data; gint sock; @@ -606,6 +619,15 @@ fd_close(sock); } +static void lock_socket_input_cb(gpointer data, + gint source, + GdkInputCondition condition) +{ + gdk_threads_enter(); + lock_socket_input_cb_locked(data, source, condition); + gdk_threads_leave(); +} + static void open_compose_new(const gchar *address, GPtrArray *attach_files) { gchar *addr = NULL; --- sylpheed-0.9.1/src/passphrase.c.alt-thread 2002-08-06 10:52:44 +0400 +++ sylpheed-0.9.1/src/passphrase.c 2003-06-05 19:44:55 +0400 @@ -269,6 +269,8 @@ static int free_passphrase(gpointer _unused) { + /* No need to call gdk_threads_enter/leave - no GDK/GTK+ access here. */ + if (last_pass != NULL) { munlock(last_pass, strlen(last_pass)); g_free(last_pass); --- sylpheed-0.9.1/src/sigstatus.c.alt-thread 2002-08-06 11:49:12 +0400 +++ sylpheed-0.9.1/src/sigstatus.c 2003-06-05 19:44:55 +0400 @@ -150,10 +150,14 @@ { GpgmegtkSigStatus hd = data; + gdk_threads_enter(); + hd->running = 0; hd->timeout_id_valid = 0; do_destroy(hd); + gdk_threads_leave(); + return FALSE; } --- sylpheed-0.9.1/src/syldap.c.alt-thread 2003-06-05 19:44:55 +0400 +++ sylpheed-0.9.1/src/syldap.c 2003-06-05 19:44:55 +0400 @@ -658,6 +658,7 @@ * main thread (the thread running the GTK event loop). */ static gint syldap_display_search_results(SyldapServer *ldapServer) { + gdk_threads_enter(); /* NOTE: when this function is called the accompanying thread should * already be terminated. */ gtk_idle_remove(ldapServer->idleId); @@ -665,6 +666,7 @@ /* FIXME: match should know whether to free this SyldapServer stuff. */ g_free(ldapServer->thread); ldapServer->thread = NULL; + gdk_threads_leave(); return TRUE; } --- sylpheed-0.9.1/src/session.c.alt-thread 2003-05-16 07:19:46 +0400 +++ sylpheed-0.9.1/src/session.c 2003-06-05 19:47:46 +0400 @@ -574,8 +574,9 @@ return SESSION_MSG_UNKNOWN; } -gboolean session_parent_input_cb(GIOChannel *source, GIOCondition condition, - gpointer data) +static gboolean session_parent_input_cb_locked(GIOChannel *source, + GIOCondition condition, + gpointer data) { Session *session = SESSION(data); gchar *msg; @@ -689,6 +690,18 @@ return TRUE; } +gboolean session_parent_input_cb(GIOChannel *source, GIOCondition condition, + gpointer data) +{ + gboolean result; + + gdk_threads_enter(); + result = session_parent_input_cb_locked(source, condition, data); + gdk_threads_leave(); + + return result; +} + gboolean session_child_input(Session *session) { gchar buf[BUFFSIZE];