call log window functions indirectly via idle callbacks
authorVladimir Nadvornik <nadvornik@suse.cz>
Sat, 12 Nov 2011 10:34:55 +0000 (11:34 +0100)
committerVladimir Nadvornik <nadvornik@suse.cz>
Sat, 12 Nov 2011 10:34:55 +0000 (11:34 +0100)
src/debug.c
src/debug.h
src/main.c

index c5848de..ed12a6a 100644 (file)
 
 #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
  */
index d5c14f2..a4f3189 100644 (file)
@@ -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 @@ 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 a60cb91..1ddee03 100644 (file)
@@ -740,7 +740,6 @@ gint main(gint argc, gchar *argv[])
        g_thread_init(NULL);
        gdk_threads_init();
        gdk_threads_enter();
-       debug_mutex = g_mutex_new();
 
 #endif