changeset 26879:7c58f6f50f16

Block/Unblock the signal handler when if it's unblocked/blocked. Trying to unblock the handler when it has not been blocked yet causes a 'handler not blocked' error message. When this message is added in the debug window, it goes into a mutex-lock from this line: gtk_list_store_append(debug_win->store, &iter); I have noticed this before on some occasions, where pidgin goes into a freeze when doing something from a signal-handler causes a debug message to be printed. Anyone knows why?
author Sadrul Habib Chowdhury <imadil@gmail.com>
date Sat, 16 May 2009 17:11:50 +0000
parents a8681646a47a
children 22b87a82755b 88c87a40a738
files pidgin/gtkimhtml.c
diffstat 1 files changed, 18 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/pidgin/gtkimhtml.c	Fri May 15 18:00:09 2009 +0000
+++ b/pidgin/gtkimhtml.c	Sat May 16 17:11:50 2009 +0000
@@ -5887,13 +5887,25 @@
 
 void gtk_imhtml_set_populate_primary_clipboard(GtkIMHtml *imhtml, gboolean populate)
 {
+	gulong signal_id;
+	signal_id = g_signal_handler_find(imhtml->text_buffer,
+			G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_UNBLOCKED, 0, 0, NULL,
+			mark_set_so_update_selection_cb, NULL);
 	if (populate) {
-		g_signal_handlers_unblock_matched(imhtml->text_buffer,
-				G_SIGNAL_MATCH_FUNC, 0, 0, NULL,
-				mark_set_so_update_selection_cb, NULL);
+		if (!signal_id) {
+			/* We didn't find an unblocked signal handler, which means there
+			   is a blocked handler. Now unblock it.
+			   This is necessary to avoid a mutex-lock when the debug message
+			   saying 'no handler is blocked' is printed in the debug window.
+				-- sad
+			 */
+			g_signal_handlers_unblock_matched(imhtml->text_buffer,
+					G_SIGNAL_MATCH_FUNC, 0, 0, NULL,
+					mark_set_so_update_selection_cb, NULL);
+		}
 	} else {
-		g_signal_handlers_block_matched(imhtml->text_buffer,
-				G_SIGNAL_MATCH_FUNC, 0, 0, NULL,
-				mark_set_so_update_selection_cb, NULL);
+		/* Block only if we found an unblocked handler */
+		if (signal_id)
+			g_signal_handler_block(imhtml->text_buffer, signal_id);
 	}
 }