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>
This commit is contained in:
parent
75c1d04650
commit
c4799f186b
20
configure.ac
20
configure.ac
|
@ -870,6 +870,26 @@ if test "x$INPUTTHREAD" = "xyes" ; then
|
||||||
SYS_LIBS="$SYS_LIBS $PTHREAD_LIBS"
|
SYS_LIBS="$SYS_LIBS $PTHREAD_LIBS"
|
||||||
CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
|
CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
|
||||||
AC_DEFINE(INPUTTHREAD, 1, [Use a separate input thread])
|
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
|
fi
|
||||||
|
|
||||||
REQUIRED_MODULES="$FIXESPROTO $DAMAGEPROTO $XCMISCPROTO $XTRANS $BIGREQSPROTO $SDK_REQUIRED_MODULES"
|
REQUIRED_MODULES="$FIXESPROTO $DAMAGEPROTO $XCMISCPROTO $XTRANS $BIGREQSPROTO $SDK_REQUIRED_MODULES"
|
||||||
|
|
|
@ -143,6 +143,12 @@
|
||||||
/* Define to 1 if you have the `mmap' function. */
|
/* Define to 1 if you have the `mmap' function. */
|
||||||
#undef HAVE_MMAP
|
#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. */
|
/* Define to 1 if you have the <ndbm.h> header file. */
|
||||||
#undef HAVE_NDBM_H
|
#undef HAVE_NDBM_H
|
||||||
|
|
||||||
|
|
|
@ -310,6 +310,12 @@ InputThreadDoWork(void *arg)
|
||||||
|
|
||||||
inputThreadInfo->running = TRUE;
|
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_add(inputThreadInfo->fds, hotplugPipeRead,
|
||||||
ospoll_trigger_level,
|
ospoll_trigger_level,
|
||||||
InputThreadPipeNotify,
|
InputThreadPipeNotify,
|
||||||
|
@ -422,6 +428,12 @@ InputThreadPreInit(void)
|
||||||
}
|
}
|
||||||
hotplugPipeWrite = hotplugPipe[1];
|
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
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue