info: use mutex to do console colors on windows
authorLRN <lrn1986 at gmail.com>
Tue, 14 Apr 2009 08:32:07 +0000 (10:32 +0200)
committerWim Taymans <wim.taymans@collabora.co.uk>
Tue, 14 Apr 2009 08:32:07 +0000 (10:32 +0200)
Use a static mutex to keep the console colors and context together when
debugging with colors on Windows.
Fixes #517231.

gst/gstinfo.c

index f0a8adb..f13b4e9 100644 (file)
@@ -792,6 +792,7 @@ gst_debug_log_default (GstDebugCategory * category, GstDebugLevel level,
 
   if (is_colored) {
 #ifndef G_OS_WIN32
+    /* colors, non-windows */
     gchar *color = NULL;
     gchar *clear;
     gchar pidcolor[10];
@@ -812,9 +813,14 @@ gst_debug_log_default (GstDebugCategory * category, GstDebugLevel level,
 #undef PRINT_FMT
     g_free (color);
 #else
+    /* colors, windows. We take a lock to keep colors and content together.
+     * Maybe there is a better way but for now this will do the right
+     * thing. */
+    static GStaticMutex win_print_mutex = G_STATIC_MUTEX_INIT;
     const gint clear = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE;
 #define SET_COLOR(c) \
   SetConsoleTextAttribute (GetStdHandle (STD_ERROR_HANDLE), (c));
+    g_static_mutex_lock (&win_print_mutex);
     /* timestamp */
     g_printerr ("%" GST_TIME_FORMAT " ", GST_TIME_ARGS (elapsed));
     /* pid */
@@ -834,8 +840,10 @@ gst_debug_log_default (GstDebugCategory * category, GstDebugLevel level,
     /* message */
     SET_COLOR (clear);
     g_printerr (" %s\n", gst_debug_message_get (message));
+    g_static_mutex_unlock (&win_print_mutex);
 #endif
   } else {
+    /* no color, all platforms */
 #define PRINT_FMT " "PID_FMT" "PTR_FMT" %s "CAT_FMT" %s\n"
     g_printerr ("%" GST_TIME_FORMAT PRINT_FMT, GST_TIME_ARGS (elapsed), pid,
         g_thread_self (), gst_debug_level_get_name (level),