gsttask: Set thread names on Windows with MSVC if a debugger is attached
authorDavid Hoyt <dhoyt@llnl.gov>
Wed, 20 Oct 2010 08:18:18 +0000 (10:18 +0200)
committerSebastian Dröge <sebastian.droege@collabora.co.uk>
Thu, 2 Dec 2010 18:02:08 +0000 (19:02 +0100)
Fixes bug #632168.

gst/gsttask.c

index 18f8869..21cadbc 100644 (file)
@@ -103,6 +103,36 @@ struct _GstTaskPrivate
   GstTaskPool *pool_id;
 };
 
+#ifdef _MSC_VER
+#include <windows.h>
+
+struct _THREADNAME_INFO
+{
+  DWORD dwType;                 // must be 0x1000
+  LPCSTR szName;                // pointer to name (in user addr space)
+  DWORD dwThreadID;             // thread ID (-1=caller thread)
+  DWORD dwFlags;                // reserved for future use, must be zero
+};
+typedef struct _THREADNAME_INFO THREADNAME_INFO;
+
+void
+SetThreadName (DWORD dwThreadID, LPCSTR szThreadName)
+{
+  THREADNAME_INFO info;
+  info.dwType = 0x1000;
+  info.szName = szThreadName;
+  info.dwThreadID = dwThreadID;
+  info.dwFlags = 0;
+
+  __try {
+    RaiseException (0x406D1388, 0, sizeof (info) / sizeof (DWORD),
+        (DWORD *) & info);
+  }
+  __except (EXCEPTION_CONTINUE_EXECUTION) {
+  }
+}
+#endif
+
 static void gst_task_finalize (GObject * object);
 
 static void gst_task_func (GstTask * task);
@@ -207,6 +237,14 @@ gst_task_configure_name (GstTask * task)
       GST_DEBUG_OBJECT (task, "Failed to set thread name");
   }
 #endif
+#ifdef _MSC_VER
+  const gchar *name;
+  name = GST_OBJECT_NAME (task);
+
+  /* set the thread name to something easily identifiable */
+  GST_DEBUG_OBJECT (task, "Setting thread name to '%s'", name);
+  SetThreadName (-1, name);
+#endif
 }
 
 static void