Skip to content

Commit 8a8cd0a

Browse files
committed
configure: Distinguish glibc and NetBSD pthread_setname_np() variants.
Reported-by: YAMAMOTO Takashi <yamt@mwd.biglobe.ne.jp> Tested-by: YAMAMOTO Takashi <yamt@mwd.biglobe.ne.jp> Signed-off-by: Ben Pfaff <blp@nicira.com>
1 parent 78f1e5c commit 8a8cd0a

3 files changed

Lines changed: 52 additions & 3 deletions

File tree

acinclude.m4

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,3 +527,50 @@ AC_DEFUN([OVS_ENABLE_SPARSE],
527527
[if test $ovs_cv_gnu_make_if = yes; then
528528
CC='$(if $(C),REAL_CC="'"$CC"'" CHECK="$(SPARSE) -I $(top_srcdir)/include/sparse $(SPARSEFLAGS) $(SPARSE_EXTRA_INCLUDES) " cgcc $(CGCCFLAGS),'"$CC"')'
529529
fi])])
530+
531+
dnl OVS_PTHREAD_SET_NAME
532+
dnl
533+
dnl This checks for three known variants of pthreads functions for setting
534+
dnl the name of the current thread:
535+
dnl
536+
dnl glibc: int pthread_setname_np(pthread_t, const char *name);
537+
dnl NetBSD: int pthread_setname_np(pthread_t, const char *format, void *arg);
538+
dnl FreeBSD: int pthread_set_name_np(pthread_t, const char *name);
539+
dnl
540+
dnl For glibc and FreeBSD, the arguments are just a thread and its name. For
541+
dnl NetBSD, 'format' is a printf() format string and 'arg' is an argument to
542+
dnl provide to it.
543+
dnl
544+
dnl This macro defines:
545+
dnl
546+
dnl glibc: HAVE_GLIBC_PTHREAD_SETNAME_NP
547+
dnl NetBSD: HAVE_NETBSD_PTHREAD_SETNAME_NP
548+
dnl FreeBSD: HAVE_PTHREAD_SET_NAME_NP
549+
AC_DEFUN([OVS_CHECK_PTHREAD_SET_NAME],
550+
[AC_CHECK_FUNCS([pthread_set_name_np])
551+
if test $ac_cv_func_pthread_set_name_np != yes; then
552+
AC_CACHE_CHECK(
553+
[for pthread_setname_np() variant],
554+
[ovs_cv_pthread_setname_np],
555+
[AC_LINK_IFELSE(
556+
[AC_LANG_PROGRAM([#include <pthread.h>
557+
], [pthread_setname_np(pthread_self(), "name");])],
558+
[ovs_cv_pthread_setname_np=glibc],
559+
[AC_LINK_IFELSE(
560+
[AC_LANG_PROGRAM([#include <pthread.h>
561+
], [pthread_setname_np(pthread_self(), "%s", "name");])],
562+
[ovs_cv_pthread_setname_np=netbsd],
563+
[ovs_cv_pthread_setname_np=none])])])
564+
case $ovs_cv_pthread_setname_np in # (
565+
glibc)
566+
AC_DEFINE(
567+
[HAVE_GLIBC_PTHREAD_SETNAME_NP], [1],
568+
[Define to 1 if pthread_setname_np() is available and takes 2 parameters (like glibc).])
569+
;; # (
570+
netbsd)
571+
AC_DEFINE(
572+
[HAVE_NETBSD_PTHREAD_SETNAME_NP], [1],
573+
[Define to 1 if pthread_setname_np() is available and takes 3 parameters (like NetBSD).])
574+
;;
575+
esac
576+
fi])

configure.ac

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,7 @@ AC_CHECK_DECLS([sys_siglist], [], [], [[#include <signal.h>]])
6464
AC_CHECK_MEMBERS([struct stat.st_mtim.tv_nsec, struct stat.st_mtimensec],
6565
[], [], [[#include <sys/stat.h>]])
6666
AC_CHECK_MEMBERS([struct ifreq.ifr_flagshigh], [], [], [[#include <net/if.h>]])
67-
AC_CHECK_FUNCS([mlockall strnlen getloadavg statvfs getmntent_r \
68-
pthread_setname_np pthread_set_name_np])
67+
AC_CHECK_FUNCS([mlockall strnlen getloadavg statvfs getmntent_r])
6968
AC_CHECK_HEADERS([mntent.h sys/statvfs.h linux/types.h linux/if_ether.h stdatomic.h])
7069
AC_CHECK_HEADERS([net/if_mib.h], [], [], [[#include <sys/types.h>
7170
#include <net/if.h>]])
@@ -89,6 +88,7 @@ OVS_CHECK_ATOMIC_ALWAYS_LOCK_FREE(2)
8988
OVS_CHECK_ATOMIC_ALWAYS_LOCK_FREE(4)
9089
OVS_CHECK_ATOMIC_ALWAYS_LOCK_FREE(8)
9190
OVS_CHECK_POSIX_AIO
91+
OVS_CHECK_PTHREAD_SET_NAME
9292

9393
OVS_ENABLE_OPTION([-Wall])
9494
OVS_ENABLE_OPTION([-Wextra])

lib/util.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,8 +401,10 @@ void
401401
set_subprogram_name(const char *name)
402402
{
403403
free(subprogram_name_set(xstrdup(name)));
404-
#if HAVE_PTHREAD_SETNAME_NP
404+
#if HAVE_GLIBC_PTHREAD_SETNAME_NP
405405
pthread_setname_np(pthread_self(), name);
406+
#elif HAVE_NETBSD_PTHREAD_SETNAME_NP
407+
pthread_setname_np(pthread_self(), "%s", name);
406408
#elif HAVE_PTHREAD_SET_NAME_NP
407409
pthread_set_name_np(pthread_self(), name);
408410
#endif

0 commit comments

Comments
 (0)