task: Add thread name support on OS X and iOS
authorIlya Konstantinov <ilya.konstantinov@gmail.com>
Sun, 1 Feb 2015 01:39:03 +0000 (03:39 +0200)
committerSebastian Dröge <sebastian@centricular.com>
Sun, 1 Feb 2015 19:11:20 +0000 (20:11 +0100)
configure.ac
gst/gsttask.c

index 46cb060..6f765ef 100644 (file)
@@ -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.h>],
+        [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])
 
index 60c0140..0f55ab9 100644 (file)
 #include <sys/prctl.h>
 #endif
 
+#ifdef HAVE_PTHREAD_SETNAME_NP_WITHOUT_TID
+#include <pthread.h>
+#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);