From 4cbe6b68b12b1102fcdc2dcec99e6b03c74291a1 Mon Sep 17 00:00:00 2001 From: Vladimir Nadvornik Date: Sat, 12 Nov 2011 11:34:55 +0100 Subject: [PATCH] call log window functions indirectly via idle callbacks --- src/debug.c | 30 +++++++++++++++++++++--------- src/debug.h | 6 +----- src/main.c | 1 - 3 files changed, 22 insertions(+), 15 deletions(-) diff --git a/src/debug.c b/src/debug.c index c5848de9..ed12a6a7 100644 --- a/src/debug.c +++ b/src/debug.c @@ -17,31 +17,43 @@ #include -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 */ diff --git a/src/debug.h b/src/debug.h index d5c14f24..a4f31891 100644 --- a/src/debug.h +++ b/src/debug.h @@ -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) diff --git a/src/main.c b/src/main.c index a60cb91a..1ddee03c 100644 --- a/src/main.c +++ b/src/main.c @@ -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 -- 2.20.1