changeset 1872:1160a9de93c2

fixed using DEBUG_N from multiple threads
author Vladimir Nadvornik <nadvornik@suse.cz>
date Sat, 09 Apr 2011 16:38:46 +0200
parents a8cdf1b5af6f
children a79da01c9e78
files src/debug.c src/debug.h src/main.c
diffstat 3 files changed, 7 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/debug.c	Thu Dec 16 22:26:36 2010 +0100
+++ b/src/debug.c	Sat Apr 09 16:38:46 2011 +0200
@@ -17,7 +17,7 @@
 
 #include <glib/gprintf.h>
 
-
+GMutex *debug_mutex;
 /*
  * Logging functions
  */
--- a/src/debug.h	Thu Dec 16 22:26:36 2010 +0100
+++ b/src/debug.h	Sat Apr 09 16:38:46 2011 +0200
@@ -17,6 +17,8 @@
 #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);
 #define log_printf(...) log_domain_printf(DOMAIN_INFO, __VA_ARGS__)
 
@@ -37,9 +39,11 @@
 				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	Thu Dec 16 22:26:36 2010 +0100
+++ b/src/main.c	Sat Apr 09 16:38:46 2011 +0200
@@ -740,6 +740,8 @@
 	g_thread_init(NULL);
 	gdk_threads_init();
 	gdk_threads_enter();
+	debug_mutex = g_mutex_new();
+
 #endif
 	
 	/* init execution time counter (debug only) */