diff options
author | Alan Coopersmith <alan.coopersmith@oracle.com> | 2016-09-10 21:14:19 -0700 |
---|---|---|
committer | Adam Jackson <ajax@redhat.com> | 2016-09-13 16:55:26 -0400 |
commit | c4799f186b31e579721f5874c897f3f46db6ad0a (patch) | |
tree | b5df363dea0c53b77836a18b0792e26cd96353cf | |
parent | 75c1d04650f63464263c159d2e95364482be724f (diff) |
os: Use pthread_setname_np to set thread names if available
Autoconf logic borrowed from glib
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Reviewed-by: Jeremy Huddleston Sequoia <jeremyhu@apple.com>
Tested-by: Jeremy Huddleston Sequoia <jeremyhu@apple.com>
-rw-r--r-- | configure.ac | 20 | ||||
-rw-r--r-- | include/dix-config.h.in | 6 | ||||
-rw-r--r-- | os/inputthread.c | 12 |
3 files changed, 38 insertions, 0 deletions
diff --git a/configure.ac b/configure.ac index e206e0fc7..4ff317f53 100644 --- a/configure.ac +++ b/configure.ac @@ -870,6 +870,26 @@ if test "x$INPUTTHREAD" = "xyes" ; then SYS_LIBS="$SYS_LIBS $PTHREAD_LIBS" CFLAGS="$CFLAGS $PTHREAD_CFLAGS" AC_DEFINE(INPUTTHREAD, 1, [Use a separate input thread]) + + save_LIBS="$LIBS" + LIBS="$LIBS $SYS_LIBS" + dnl MacOS X 10.6 & higher + 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 GNU libc 2.12 & higher, Solaris 11.3 & higher + AC_MSG_CHECKING(for pthread_setname_np(pthread_t, const char*)) + AC_LINK_IFELSE([AC_LANG_PROGRAM([#include <pthread.h>], + [pthread_setname_np(pthread_self(), "example")])], + [AC_MSG_RESULT(yes) + AC_DEFINE(HAVE_PTHREAD_SETNAME_NP_WITH_TID,1, + [Have function pthread_setname_np(pthread_t, const char*)])], + [AC_MSG_RESULT(no)]) + LIBS="$save_LIBS" fi REQUIRED_MODULES="$FIXESPROTO $DAMAGEPROTO $XCMISCPROTO $XTRANS $BIGREQSPROTO $SDK_REQUIRED_MODULES" diff --git a/include/dix-config.h.in b/include/dix-config.h.in index d49af928f..4f020e5d8 100644 --- a/include/dix-config.h.in +++ b/include/dix-config.h.in @@ -143,6 +143,12 @@ /* Define to 1 if you have the `mmap' function. */ #undef HAVE_MMAP +/* Define to 1 if you have the function pthread_setname_np(const char*) */ +#undef HAVE_PTHREAD_SETNAME_NP_WITHOUT_TID + +/* Define to 1 if you have the function pthread_setname_np(pthread_t, const char*) */ +#undef HAVE_PTHREAD_SETNAME_NP_WITH_TID + /* Define to 1 if you have the <ndbm.h> header file. */ #undef HAVE_NDBM_H diff --git a/os/inputthread.c b/os/inputthread.c index 6b379f5ea..6aa0a9ce6 100644 --- a/os/inputthread.c +++ b/os/inputthread.c @@ -310,6 +310,12 @@ InputThreadDoWork(void *arg) inputThreadInfo->running = TRUE; +#if defined(HAVE_PTHREAD_SETNAME_NP_WITH_TID) + pthread_setname_np (pthread_self(), "InputThread"); +#elif defined(HAVE_PTHREAD_SETNAME_NP_WITHOUT_TID) + pthread_setname_np ("InputThread"); +#endif + ospoll_add(inputThreadInfo->fds, hotplugPipeRead, ospoll_trigger_level, InputThreadPipeNotify, @@ -422,6 +428,12 @@ InputThreadPreInit(void) } hotplugPipeWrite = hotplugPipe[1]; +#if defined(HAVE_PTHREAD_SETNAME_NP_WITH_TID) + pthread_setname_np (pthread_self(), "MainThread"); +#elif defined(HAVE_PTHREAD_SETNAME_NP_WITHOUT_TID) + pthread_setname_np ("MainThread"); +#endif + } /** |