From f9c74afe62516cad710067de9db2e1a38fb186f4 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Mon, 15 Mar 2010 14:48:19 +0100 Subject: [PATCH] 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. --- configure.ac | 4 ++++ gst/gsttask.c | 36 ++++++++++++++++++++++++++++++++---- 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/configure.ac b/configure.ac index 2dbe9d9..37967e3 100644 --- a/configure.ac +++ b/configure.ac @@ -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 diff --git a/gst/gsttask.c b/gst/gsttask.c index 86059ed..676ed20 100644 --- a/gst/gsttask.c +++ b/gst/gsttask.c @@ -34,7 +34,7 @@ * is typically done when the demuxer can perform random access on the upstream * peer element for improved performance. * - * Although convenience functions exist on #GstPad to start/pause/stop tasks, it + * Although convenience functions exist on #GstPad to start/pause/stop tasks, it * might sometimes be needed to create a #GstTask manually if it is not related to * a #GstPad. * @@ -68,6 +68,10 @@ #include "gstinfo.h" #include "gsttask.h" +#ifdef HAVE_SYS_PRCTL_H +#include +#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; @@ -257,8 +285,8 @@ exit: g_thread_set_priority (tself, G_THREAD_PRIORITY_NORMAL); } /* now we allow messing with the lock again by setting the running flag to - * FALSE. Together with the SIGNAL this is the sign for the _join() to - * complete. + * FALSE. Together with the SIGNAL this is the sign for the _join() to + * complete. * Note that we still have not dropped the final ref on the task. We could * check here if there is a pending join() going on and drop the last ref * before releasing the lock as we can be sure that a ref is held by the @@ -709,7 +737,7 @@ gst_task_pause (GstTask * task) * The task will automatically be stopped with this call. * * This function cannot be called from within a task function as this - * would cause a deadlock. The function will detect this and print a + * would cause a deadlock. The function will detect this and print a * g_warning. * * Returns: %TRUE if the task could be joined. -- 2.7.4