task: configure the object name as thread name

When we have prctl available, use it to set the configured object name as the
thread name for better debugging.

Based on patch by Robert Swain.
This commit is contained in:
Wim Taymans 2010-03-15 14:48:19 +01:00
parent f089c3cceb
commit f9c74afe62
2 changed files with 36 additions and 4 deletions

View file

@ -281,6 +281,10 @@ dnl check for pthreads
AC_CHECK_HEADERS([pthread.h], HAVE_PTHREAD_H=yes)
AM_CONDITIONAL(HAVE_PTHREAD_H, test "x$HAVE_PTHREAD_H" = "xyes")
dnl check for sys/prctl
AC_CHECK_HEADERS([sys/prctl.h], HAVE_SYS_PRCTL_H=yes)
AM_CONDITIONAL(HAVE_SYS_PRTCL_H, test "x$HAVE_SYS_PRCTL_H" = "xyes")
dnl Check for valgrind.h
dnl separate from HAVE_VALGRIND because you can have the program, but not
dnl the dev package

View file

@ -68,6 +68,10 @@
#include "gstinfo.h"
#include "gsttask.h"
#ifdef HAVE_SYS_PRCTL_H
#include <sys/prctl.h>
#endif
GST_DEBUG_CATEGORY_STATIC (task_debug);
#define GST_CAT_DEFAULT (task_debug)
@ -177,6 +181,27 @@ gst_task_finalize (GObject * object)
G_OBJECT_CLASS (gst_task_parent_class)->finalize (object);
}
/* should be called with the object LOCK */
static void
gst_task_configure_name (GstTask * task)
{
#ifdef HAVE_SYS_PRCTL_H
const gchar *name;
gchar thread_name[17] = { 0, };
name = GST_OBJECT_NAME (task);
/* set the thread name to something easily identifiable */
if (!snprintf (thread_name, 17, "%s", GST_STR_NULL (name))) {
GST_DEBUG_OBJECT (task, "Could not create thread name for '%s'", name);
} else {
GST_DEBUG_OBJECT (task, "Setting thread name to '%s'", thread_name);
if (prctl (PR_SET_NAME, (unsigned long int) thread_name))
GST_DEBUG_OBJECT (task, "Failed to set thread name");
}
#endif
}
static void
gst_task_func (GstTask * task)
{
@ -212,6 +237,9 @@ gst_task_func (GstTask * task)
/* locking order is TASK_LOCK, LOCK */
g_static_rec_mutex_lock (lock);
GST_OBJECT_LOCK (task);
/* configure the thread name now */
gst_task_configure_name (task);
while (G_LIKELY (task->state != GST_TASK_STOPPED)) {
while (G_UNLIKELY (task->state == GST_TASK_PAUSED)) {
gint t;