From 05296b35a526a425d24cd0ced8de8df9dc71243b Mon Sep 17 00:00:00 2001 From: Ilya Konstantinov Date: Sun, 1 Feb 2015 03:39:03 +0200 Subject: [PATCH] task: Add thread name support on OS X and iOS --- configure.ac | 12 ++++++++++++ gst/gsttask.c | 19 +++++++++++++++++-- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/configure.ac b/configure.ac index 46cb060823..6f765ef0a0 100644 --- a/configure.ac +++ b/configure.ac @@ -346,6 +346,18 @@ AM_CONDITIONAL(HAVE_PTHREAD, test "x$ax_pthread_ok" = "xyes") dnl check for sys/prctl for setting thread name on Linux AC_CHECK_HEADERS([sys/prctl.h], [], [], [AC_INCLUDES_DEFAULT]) +dnl check for pthread_setname_np(const char*) +dnl which is present on OS X 10.6, iOS 3.2 and above +AC_MSG_CHECKING(for pthread_setname_np(const char*)) +AC_LINK_IFELSE( + [AC_LANG_PROGRAM( + [#include ], + [pthread_setname_np("example")])], + [AC_MSG_RESULT(yes) + AC_DEFINE(HAVE_PTHREAD_SETNAME_NP_WITHOUT_TID,1, + [Have function pthread_setname_np(const char*)])], + [AC_MSG_RESULT(no)]) + dnl check for sys/uio.h for writev() AC_CHECK_HEADERS([sys/uio.h], [], [], [AC_INCLUDES_DEFAULT]) diff --git a/gst/gsttask.c b/gst/gsttask.c index 60c01400cf..0f55ab9b99 100644 --- a/gst/gsttask.c +++ b/gst/gsttask.c @@ -78,6 +78,10 @@ #include #endif +#ifdef HAVE_PTHREAD_SETNAME_NP_WITHOUT_TID +#include +#endif + GST_DEBUG_CATEGORY_STATIC (task_debug); #define GST_CAT_DEFAULT (task_debug) @@ -246,8 +250,19 @@ gst_task_configure_name (GstTask * task) GST_DEBUG_OBJECT (task, "Failed to set thread name"); } GST_OBJECT_UNLOCK (task); -#endif -#ifdef _MSC_VER +#elif defined(HAVE_PTHREAD_SETNAME_NP_WITHOUT_TID) + const gchar *name; + + GST_OBJECT_LOCK (task); + name = GST_OBJECT_NAME (task); + + /* set the thread name to something easily identifiable */ + GST_DEBUG_OBJECT (task, "Setting thread name to '%s'", name); + if (pthread_setname_np (name)) + GST_DEBUG_OBJECT (task, "Failed to set thread name"); + + GST_OBJECT_UNLOCK (task); +#elif _MSC_VER const gchar *name; name = GST_OBJECT_NAME (task);