[PATCH 4/8] thread-posix: use pthread_(get|set)name_np() if available

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Newer generations of libpthread have functions to set and get the thread
names. If available, use them.
---
 configure.ac                 |    4 +++-
 src/pulsecore/thread-posix.c |   15 ++++++++++++---
 2 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/configure.ac b/configure.ac
index e2b5a6a..6f262fb 100644
--- a/configure.ac
+++ b/configure.ac
@@ -448,6 +448,8 @@ AC_SEARCH_LIBS([shm_open], [rt])
 AC_SEARCH_LIBS([inet_ntop], [nsl])
 AC_SEARCH_LIBS([timer_create], [rt])
 AC_SEARCH_LIBS([pthread_setaffinity_np], [pthread])
+AC_SEARCH_LIBS([pthread_getname_np], [pthread])
+AC_SEARCH_LIBS([pthread_setname_np], [pthread])
 
 # BSD
 AC_SEARCH_LIBS([connect], [socket])
@@ -489,7 +491,7 @@ AC_FUNC_SELECT_ARGTYPES
 AC_CHECK_FUNCS_ONCE([chmod chown fstat fchown fchmod clock_gettime getaddrinfo getgrgid_r getgrnam_r \
     getpwnam_r getpwuid_r gettimeofday getuid mlock nanosleep \
     pipe posix_fadvise posix_madvise posix_memalign setpgid setsid shm_open \
-    sigaction sleep symlink sysconf uname pthread_setaffinity_np])
+    sigaction sleep symlink sysconf uname pthread_setaffinity_np pthread_getname_np pthread_setname_np])
 AC_CHECK_FUNCS([mkfifo], [HAVE_MKFIFO=1], [HAVE_MKFIFO=0])
 
 AM_CONDITIONAL(HAVE_MKFIFO, test "x$HAVE_MKFIFO" = "x1")
diff --git a/src/pulsecore/thread-posix.c b/src/pulsecore/thread-posix.c
index 7d5252d..ae73267 100644
--- a/src/pulsecore/thread-posix.c
+++ b/src/pulsecore/thread-posix.c
@@ -71,7 +71,9 @@ static void* internal_thread_func(void *userdata) {
     pa_thread *t = userdata;
     pa_assert(t);
 
-#ifdef __linux__
+#ifdef HAVE_PTHREAD_SETNAME_NP
+    pthread_setname_np(t->name);
+#elif defined(__linux__)
     prctl(PR_SET_NAME, t->name);
 #endif
 
@@ -175,7 +177,9 @@ void pa_thread_set_name(pa_thread *t, const char *name) {
     pa_xfree(t->name);
     t->name = pa_xstrdup(name);
 
-#ifdef __linux__
+#ifdef HAVE_PTHREAD_SETNAME_NP
+    pthread_setname_np(name);
+#elif defined(__linux__)
     prctl(PR_SET_NAME, name);
 #endif
 }
@@ -183,7 +187,12 @@ void pa_thread_set_name(pa_thread *t, const char *name) {
 const char *pa_thread_get_name(pa_thread *t) {
     pa_assert(t);
 
-#ifdef __linux__
+#ifdef HAVE_PTHREAD_GETNAME_NP
+    if (!t->name) {
+        t->name = pa_xmalloc0(17);
+        pthread_getname_np(t->id, t->name, 16);
+    }
+#elif defined(__linux__)
     if (!t->name) {
         t->name = pa_xmalloc(17);
 
-- 
1.7.1




[Index of Archives]     [Linux Audio Users]     [AMD Graphics]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux