changeset 1937:b7ecaec17b74

call log window functions indirectly via idle callbacks
author Vladimir Nadvornik <nadvornik@suse.cz>
date Sat, 12 Nov 2011 11:34:55 +0100
parents ed6aa14b66c9
children ee4f2e54d806
files src/debug.c src/debug.h src/main.c
diffstat 3 files changed, 22 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/src/debug.c	Tue Oct 04 22:09:55 2011 +0200
+++ b/src/debug.c	Sat Nov 12 11:34:55 2011 +0100
@@ -17,31 +17,43 @@
 
 #include <glib/gprintf.h>
 
-GMutex *debug_mutex;
 /*
  * Logging functions
  */
 
-gint log_domain_printf(const gchar *domain, const gchar *format, ...)
+static gboolean log_msg_cb(gpointer data)
+{
+	gchar *buf = data;
+	log_window_append(buf, LOG_MSG);
+	g_free(buf);
+	return FALSE;
+}
+
+static gboolean log_normal_cb(gpointer data)
+{
+	gchar *buf = data;
+	log_window_append(buf, LOG_NORMAL);
+	g_free(buf);
+	return FALSE;
+}
+
+void log_domain_printf(const gchar *domain, const gchar *format, ...)
 {
 	va_list ap;
-	gchar buf[4096];
-	gint ret;
+	gchar *buf;
 
 	va_start(ap, format);
-	ret = g_vsnprintf(buf, sizeof(buf), format, ap);
+	buf = g_strdup_vprintf(format, ap);
 	va_end(ap);
 
 	print_term(buf);
 	if (strcmp(domain, DOMAIN_INFO) == 0)
-		log_window_append(buf, LOG_NORMAL);
+		g_idle_add(log_normal_cb, buf);
 	else
-		log_window_append(buf, LOG_MSG);
+		g_idle_add(log_msg_cb, buf);
 
-	return ret;
 }
 
-
 /*
  * Debugging only functions
  */
--- a/src/debug.h	Tue Oct 04 22:09:55 2011 +0200
+++ b/src/debug.h	Sat Nov 12 11:34:55 2011 +0100
@@ -17,9 +17,7 @@
 #define DOMAIN_DEBUG "debug"
 #define DOMAIN_INFO  "info"
 
-extern GMutex *debug_mutex;
-
-gint log_domain_printf(const gchar *domain, const gchar *format, ...) G_GNUC_PRINTF(2, 3);
+void log_domain_printf(const gchar *domain, const gchar *format, ...) G_GNUC_PRINTF(2, 3);
 #define log_printf(...) log_domain_printf(DOMAIN_INFO, __VA_ARGS__)
 
 #ifdef DEBUG
@@ -39,11 +37,9 @@
 				gint debug_level = get_debug_level(); \
 				if (debug_level >= (n)) 	\
 					{ 		\
-					g_mutex_lock(debug_mutex); \
 					if (debug_level != 1) log_domain_printf(DOMAIN_DEBUG, "%s:%d: ", __FILE__, __LINE__); \
 					log_domain_printf(DOMAIN_DEBUG, __VA_ARGS__); \
 					log_domain_printf(DOMAIN_DEBUG, "\n"); \
-					g_mutex_unlock(debug_mutex); \
 					} \
 				} while (0)
 
--- a/src/main.c	Tue Oct 04 22:09:55 2011 +0200
+++ b/src/main.c	Sat Nov 12 11:34:55 2011 +0100
@@ -740,7 +740,6 @@
 	g_thread_init(NULL);
 	gdk_threads_init();
 	gdk_threads_enter();
-	debug_mutex = g_mutex_new();
 
 #endif