thread-posix: Use pthread_(get|set)name_np() if available

Newer generations of libpthread have functions to set and get the thread
names. If available, use them.
This commit is contained in:
Daniel Mack 2011-04-22 04:28:11 +02:00 committed by Colin Guthrie
parent 98f2209663
commit 2411d9accd
2 changed files with 12 additions and 1 deletions

View file

@ -448,6 +448,8 @@ AC_SEARCH_LIBS([shm_open], [rt])
AC_SEARCH_LIBS([inet_ntop], [nsl]) AC_SEARCH_LIBS([inet_ntop], [nsl])
AC_SEARCH_LIBS([timer_create], [rt]) AC_SEARCH_LIBS([timer_create], [rt])
AC_SEARCH_LIBS([pthread_setaffinity_np], [pthread]) AC_SEARCH_LIBS([pthread_setaffinity_np], [pthread])
AC_SEARCH_LIBS([pthread_getname_np], [pthread])
AC_SEARCH_LIBS([pthread_setname_np], [pthread])
# BSD # BSD
AC_SEARCH_LIBS([connect], [socket]) 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 \ AC_CHECK_FUNCS_ONCE([chmod chown fstat fchown fchmod clock_gettime getaddrinfo getgrgid_r getgrnam_r \
getpwnam_r getpwuid_r gettimeofday getuid mlock nanosleep \ getpwnam_r getpwuid_r gettimeofday getuid mlock nanosleep \
pipe posix_fadvise posix_madvise posix_memalign setpgid setsid shm_open \ 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]) AC_CHECK_FUNCS([mkfifo], [HAVE_MKFIFO=1], [HAVE_MKFIFO=0])
AM_CONDITIONAL(HAVE_MKFIFO, test "x$HAVE_MKFIFO" = "x1") AM_CONDITIONAL(HAVE_MKFIFO, test "x$HAVE_MKFIFO" = "x1")

View file

@ -73,6 +73,8 @@ static void* internal_thread_func(void *userdata) {
#ifdef __linux__ #ifdef __linux__
prctl(PR_SET_NAME, t->name); prctl(PR_SET_NAME, t->name);
#elif defined(HAVE_PTHREAD_SETNAME_NP) && defined(OS_IS_DARWIN)
pthread_setname_np(t->name);
#endif #endif
t->id = pthread_self(); t->id = pthread_self();
@ -177,6 +179,8 @@ void pa_thread_set_name(pa_thread *t, const char *name) {
#ifdef __linux__ #ifdef __linux__
prctl(PR_SET_NAME, name); prctl(PR_SET_NAME, name);
#elif defined(HAVE_PTHREAD_SETNAME_NP) && defined(OS_IS_DARWIN)
pthread_setname_np(name);
#endif #endif
} }
@ -194,6 +198,11 @@ const char *pa_thread_get_name(pa_thread *t) {
t->name = NULL; t->name = NULL;
} }
} }
#elif defined(HAVE_PTHREAD_GETNAME_NP) && defined(OS_IS_DARWIN)
if (!t->name) {
t->name = pa_xmalloc0(17);
pthread_getname_np(t->id, t->name, 16);
}
#endif #endif
return t->name; return t->name;