Skip to content

Commit

Permalink
configure: Distinguish glibc and NetBSD pthread_setname_np() variants.
Browse files Browse the repository at this point in the history
Reported-by: YAMAMOTO Takashi <[email protected]>
Tested-by: YAMAMOTO Takashi <[email protected]>
Signed-off-by: Ben Pfaff <[email protected]>
  • Loading branch information
blp committed Aug 1, 2013
1 parent 78f1e5c commit 8a8cd0a
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 3 deletions.
47 changes: 47 additions & 0 deletions acinclude.m4
Original file line number Diff line number Diff line change
Expand Up @@ -527,3 +527,50 @@ AC_DEFUN([OVS_ENABLE_SPARSE],
[if test $ovs_cv_gnu_make_if = yes; then
CC='$(if $(C),REAL_CC="'"$CC"'" CHECK="$(SPARSE) -I $(top_srcdir)/include/sparse $(SPARSEFLAGS) $(SPARSE_EXTRA_INCLUDES) " cgcc $(CGCCFLAGS),'"$CC"')'
fi])])

dnl OVS_PTHREAD_SET_NAME
dnl
dnl This checks for three known variants of pthreads functions for setting
dnl the name of the current thread:
dnl
dnl glibc: int pthread_setname_np(pthread_t, const char *name);
dnl NetBSD: int pthread_setname_np(pthread_t, const char *format, void *arg);
dnl FreeBSD: int pthread_set_name_np(pthread_t, const char *name);
dnl
dnl For glibc and FreeBSD, the arguments are just a thread and its name. For
dnl NetBSD, 'format' is a printf() format string and 'arg' is an argument to
dnl provide to it.
dnl
dnl This macro defines:
dnl
dnl glibc: HAVE_GLIBC_PTHREAD_SETNAME_NP
dnl NetBSD: HAVE_NETBSD_PTHREAD_SETNAME_NP
dnl FreeBSD: HAVE_PTHREAD_SET_NAME_NP
AC_DEFUN([OVS_CHECK_PTHREAD_SET_NAME],
[AC_CHECK_FUNCS([pthread_set_name_np])
if test $ac_cv_func_pthread_set_name_np != yes; then
AC_CACHE_CHECK(
[for pthread_setname_np() variant],
[ovs_cv_pthread_setname_np],
[AC_LINK_IFELSE(
[AC_LANG_PROGRAM([#include <pthread.h>
], [pthread_setname_np(pthread_self(), "name");])],
[ovs_cv_pthread_setname_np=glibc],
[AC_LINK_IFELSE(
[AC_LANG_PROGRAM([#include <pthread.h>
], [pthread_setname_np(pthread_self(), "%s", "name");])],
[ovs_cv_pthread_setname_np=netbsd],
[ovs_cv_pthread_setname_np=none])])])
case $ovs_cv_pthread_setname_np in # (
glibc)
AC_DEFINE(
[HAVE_GLIBC_PTHREAD_SETNAME_NP], [1],
[Define to 1 if pthread_setname_np() is available and takes 2 parameters (like glibc).])
;; # (
netbsd)
AC_DEFINE(
[HAVE_NETBSD_PTHREAD_SETNAME_NP], [1],
[Define to 1 if pthread_setname_np() is available and takes 3 parameters (like NetBSD).])
;;
esac
fi])
4 changes: 2 additions & 2 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,7 @@ AC_CHECK_DECLS([sys_siglist], [], [], [[#include <signal.h>]])
AC_CHECK_MEMBERS([struct stat.st_mtim.tv_nsec, struct stat.st_mtimensec],
[], [], [[#include <sys/stat.h>]])
AC_CHECK_MEMBERS([struct ifreq.ifr_flagshigh], [], [], [[#include <net/if.h>]])
AC_CHECK_FUNCS([mlockall strnlen getloadavg statvfs getmntent_r \
pthread_setname_np pthread_set_name_np])
AC_CHECK_FUNCS([mlockall strnlen getloadavg statvfs getmntent_r])
AC_CHECK_HEADERS([mntent.h sys/statvfs.h linux/types.h linux/if_ether.h stdatomic.h])
AC_CHECK_HEADERS([net/if_mib.h], [], [], [[#include <sys/types.h>
#include <net/if.h>]])
Expand All @@ -89,6 +88,7 @@ OVS_CHECK_ATOMIC_ALWAYS_LOCK_FREE(2)
OVS_CHECK_ATOMIC_ALWAYS_LOCK_FREE(4)
OVS_CHECK_ATOMIC_ALWAYS_LOCK_FREE(8)
OVS_CHECK_POSIX_AIO
OVS_CHECK_PTHREAD_SET_NAME

OVS_ENABLE_OPTION([-Wall])
OVS_ENABLE_OPTION([-Wextra])
Expand Down
4 changes: 3 additions & 1 deletion lib/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -401,8 +401,10 @@ void
set_subprogram_name(const char *name)
{
free(subprogram_name_set(xstrdup(name)));
#if HAVE_PTHREAD_SETNAME_NP
#if HAVE_GLIBC_PTHREAD_SETNAME_NP
pthread_setname_np(pthread_self(), name);
#elif HAVE_NETBSD_PTHREAD_SETNAME_NP
pthread_setname_np(pthread_self(), "%s", name);
#elif HAVE_PTHREAD_SET_NAME_NP
pthread_set_name_np(pthread_self(), name);
#endif
Expand Down

0 comments on commit 8a8cd0a

Please sign in to comment.