fixed using DEBUG_N from multiple threads
authorVladimir Nadvornik <nadvornik@suse.cz>
Sat, 9 Apr 2011 14:38:46 +0000 (16:38 +0200)
committerVladimir Nadvornik <nadvornik@suse.cz>
Tue, 27 Sep 2011 12:19:02 +0000 (14:19 +0200)
src/debug.c
src/debug.h
src/main.c

index 0111819..c5848de 100644 (file)
@@ -17,7 +17,7 @@
 
 #include <glib/gprintf.h>
 
-
+GMutex *debug_mutex;
 /*
  * Logging functions
  */
index 71f1497..d5c14f2 100644 (file)
@@ -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 @@ void init_exec_time(void);
                                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)
 
index 7cad734..b74235d 100644 (file)
@@ -740,6 +740,8 @@ gint main(gint argc, gchar *argv[])
        g_thread_init(NULL);
        gdk_threads_init();
        gdk_threads_enter();
+       debug_mutex = g_mutex_new();
+
 #endif
        
        /* init execution time counter (debug only) */