You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by so...@apache.org on 2013/05/16 23:57:25 UTC

[06/47] git commit: TS-1880: add pthread_setname_np support

TS-1880: add pthread_setname_np support


Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo
Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/96d979d9
Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/96d979d9
Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/96d979d9

Branch: refs/heads/sphinx-docs
Commit: 96d979d97129c4ba5f7d45d5b323267a4fb62049
Parents: aeb7442
Author: James Peach <jp...@apache.org>
Authored: Fri May 3 19:36:26 2013 -0700
Committer: James Peach <jp...@apache.org>
Committed: Mon May 6 12:02:30 2013 -0700

----------------------------------------------------------------------
 CHANGES                                  |    2 +
 configure.ac                             |   63 +++++++++++++++++++++++++
 iocore/eventsystem/UnixEventProcessor.cc |    4 --
 lib/ts/ink_thread.h                      |   14 +++++-
 4 files changed, 77 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/trafficserver/blob/96d979d9/CHANGES
----------------------------------------------------------------------
diff --git a/CHANGES b/CHANGES
index 265eb4f..e932443 100644
--- a/CHANGES
+++ b/CHANGES
@@ -2,6 +2,8 @@
   Changes with Apache Traffic Server 3.3.3
 
 
+  *) [TS-1880] Use pthread_setname_np to set the thread name on multiple platforms.
+
   *) [TS-1879] Make the Ptr<> conversion constructor explicit.
 
   *) [TS-1768] Prefer AC_SEARCH_LIBS to AC_CHECK_LIB to avoid unnecessary linking.

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/96d979d9/configure.ac
----------------------------------------------------------------------
diff --git a/configure.ac b/configure.ac
index c1b2783..fe90f88 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1342,6 +1342,7 @@ TS_FLAG_HEADERS([sys/epoll.h \
                   sys/param.h \
                   sys/pset.h \
                   sched.h \
+                  pthread.h \
                   pthread_np.h \
                   machine/endian.h \
                   endian.h \
@@ -1477,6 +1478,68 @@ TS_FLAG_HEADERS([netinet/ip_icmp.h], [], [],
 AC_SUBST(netinet_iph)
 AC_SUBST(netinet_ip_icmph)
 
+# Test for additional pthread interfaces.
+
+# Darwin pthread_setname_np:
+AC_MSG_CHECKING([for 1-parameter version of pthread_setname_np()])
+AC_COMPILE_IFELSE([
+    AC_LANG_PROGRAM([
+#if HAVE_PTHREAD_H
+#include <pthread.h>
+#endif
+#if PTHREAD_NP_H
+#include <pthread_np.h>
+#endif
+      ], [
+        pthread_setname_np("conftest");
+    ])
+  ], [
+    AC_DEFINE(HAVE_PTHREAD_SETNAME_NP_1, 1, [Whether the 1 parameter version of pthread_setname_np() is available])
+    AC_MSG_RESULT([yes])
+  ], [
+    AC_MSG_RESULT([no])
+])
+
+# Linux pthread_setname_np:
+AC_MSG_CHECKING([for 2-parameter version of pthread_setname_np()])
+AC_COMPILE_IFELSE([
+    AC_LANG_PROGRAM([
+#if HAVE_PTHREAD_H
+#include <pthread.h>
+#endif
+#if PTHREAD_NP_H
+#include <pthread_np.h>
+#endif
+      ], [
+        pthread_setname_np(pthread_self(), "conftest");
+    ])
+  ], [
+    AC_DEFINE(HAVE_PTHREAD_SETNAME_NP_2, 1, [Whether the 2 parameter version of pthread_setname_np() is available])
+    AC_MSG_RESULT([yes])
+  ], [
+    AC_MSG_RESULT([no])
+])
+
+# BSD pthread_set_name_np:
+AC_MSG_CHECKING([for 2-parameter version of pthread_set_name_np()])
+AC_COMPILE_IFELSE([
+    AC_LANG_PROGRAM([
+#if HAVE_PTHREAD_H
+#include <pthread.h>
+#endif
+#if PTHREAD_NP_H
+#include <pthread_np.h>
+#endif
+      ], [
+        pthread_set_name_np(pthread_self(), "conftest");
+    ])
+  ], [
+    AC_DEFINE(HAVE_PTHREAD_SET_NAME_NP_2, 1, [Whether the 2 parameter version of pthread_set_name_np() is available])
+    AC_MSG_RESULT([yes])
+  ], [
+    AC_MSG_RESULT([no])
+])
+
 # BSD-derived systems populate the socket length in the structure itself. It's
 # redundant to check all of these, but hey, I need the typing practice.
 AC_CHECK_MEMBER([struct sockaddr.sa_len], [], [], [#include <netinet/in.h>])

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/96d979d9/iocore/eventsystem/UnixEventProcessor.cc
----------------------------------------------------------------------
diff --git a/iocore/eventsystem/UnixEventProcessor.cc b/iocore/eventsystem/UnixEventProcessor.cc
index 8613cd3..ac03170 100644
--- a/iocore/eventsystem/UnixEventProcessor.cc
+++ b/iocore/eventsystem/UnixEventProcessor.cc
@@ -47,10 +47,6 @@ typedef cpuset_t ink_cpuset_t;
 #define PTR_FMT "p"
 #endif
 
-#if HAVE_PTHREAD_NP_H
-#include <pthread_np.h>
-#endif
-
 #if HAVE_SYS_PSET_H
 #include <sys/pset.h>
 typedef psetid_t ink_cpuset_t;

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/96d979d9/lib/ts/ink_thread.h
----------------------------------------------------------------------
diff --git a/lib/ts/ink_thread.h b/lib/ts/ink_thread.h
index 18cee66..25fc59a 100644
--- a/lib/ts/ink_thread.h
+++ b/lib/ts/ink_thread.h
@@ -46,6 +46,10 @@
 #include <signal.h>
 #include <semaphore.h>
 
+#if TS_HAVE_PTHREAD_NP_H
+#include <pthread_np.h>
+#endif
+
 #define INK_MUTEX_INIT PTHREAD_MUTEX_INITIALIZER
 
 typedef pthread_t ink_thread;
@@ -317,9 +321,15 @@ ink_create_pipe( int pfd[2])
 static inline void
 ink_set_thread_name(const char* name ATS_UNUSED)
 {
-#if defined(HAVE_SYS_PRCTL_H) && defined(PR_SET_NAME)
+#if defined(HAVE_PTHREAD_SETNAME_NP_1)
+  pthread_setname_np(name);
+#elif defined(HAVE_PTHREAD_SETNAME_NP_2)
+  pthread_setname_np(pthread_self(), name);
+#elif defined(HAVE_PTHREAD_SET_NAME_NP_2)
+  pthread_set_name_np(pthread_self(), name);
+#elif defined(HAVE_SYS_PRCTL_H) && defined(PR_SET_NAME)
   prctl(PR_SET_NAME, name, 0, 0, 0);
-#endif /* no prctl.h and PR_SET_NAME not supported */
+#endif
 }
 
 #endif /* #if defined(POSIX_THREAD) */