gsttask: Set thread names on Windows with MSVC if a debugger is attached

Fixes bug #632168.
This commit is contained in:
David Hoyt 2010-10-20 10:18:18 +02:00 committed by Sebastian Dröge
parent a797b9f22b
commit 7199a4f1ff

View 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