[PATCH:xserver] Use pthread_setname_np to set thread names if available
Jeremy Huddleston Sequoia
jeremyhu at apple.com
Sun Sep 11 08:28:46 UTC 2016
Reviewed-by: Jeremy Huddleston Sequoia <jeremyhu at apple.com>
Tested-by: Jeremy Huddleston Sequoia <jeremyhu at apple.com>
(on current macOS)
> On Sep 10, 2016, at 21:14, Alan Coopersmith <alan.coopersmith at oracle.com> wrote:
>
> Autoconf logic borrowed from glib
>
> Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
> ---
> configure.ac | 20 ++++++++++++++++++++
> include/dix-config.h.in | 6 ++++++
> os/inputthread.c | 12 ++++++++++++
> 3 files changed, 38 insertions(+)
>
> I have only tested this on Solaris, not MacOS or Linux, but since the
> similar code in glib works on both, hope this will too.
>
> diff --git a/configure.ac b/configure.ac
> index e206e0f..4ff317f 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 d49af92..4f020e5 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 1cd1c2a..2ea39e7 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,
> @@ -411,6 +417,12 @@ InputThreadPreInit(void)
> fcntl(hotplugPipeRead, F_SETFL, O_NONBLOCK | O_CLOEXEC);
> 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
> +
> }
>
> /**
> --
> 2.7.4
>
> _______________________________________________
> xorg-devel at lists.x.org: X.Org development
> Archives: http://lists.x.org/archives/xorg-devel
> Info: https://lists.x.org/mailman/listinfo/xorg-devel
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 4465 bytes
Desc: not available
URL: <https://lists.x.org/archives/xorg-devel/attachments/20160911/de4b1858/attachment.bin>
More information about the xorg-devel
mailing list