Commit c4799f18 authored by Alan Coopersmith's avatar Alan Coopersmith Committed by Adam Jackson

os: Use pthread_setname_np to set thread names if available

Autoconf logic borrowed from glib
Signed-off-by: Alan Coopersmith's avatarAlan Coopersmith <alan.coopersmith@oracle.com>
Reviewed-by: Jeremy Huddleston Sequoia's avatarJeremy Huddleston Sequoia <jeremyhu@apple.com>
Tested-by: Jeremy Huddleston Sequoia's avatarJeremy Huddleston Sequoia <jeremyhu@apple.com>
parent 75c1d046
......@@ -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"
......
......@@ -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
......
......@@ -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
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment