build: rely on gnulib's pthread module

Gnulib can guarantee that pthread.h exists, but for now, it is a dummy
header with no support for most pthread_* functions.  Modify our
use of pthread to use function checks, rather than header checks,
to determine how much pthread support is present.

* bootstrap.conf (gnulib_modules): Add pthread.
* configure.ac: Drop all pthread.h checks.  Optimize function
checks.  Add check for pthread functions.
* src/Makefile.am (libvirt_lxc_LDADD): Ensure proper link.
* src/remote/remote_driver.c (remoteIOEventLoop): Depend on
pthread_sigmask, now that gnulib guarantees pthread.h.
* src/util/util.c (virFork): Likewise.
* src/util/threads.c (threads-pthread.c): Depend on
pthread_mutexattr_init, as a witness of full pthread support.
* src/util/threads.h (threads-pthread.h): Likewise.
This commit is contained in:
Eric Blake 2010-04-28 20:39:11 -06:00
parent 2256d8b86e
commit 9017b9bcaf
7 changed files with 26 additions and 23 deletions

View File

@ -43,6 +43,7 @@ perror
physmem physmem
poll poll
posix-shell posix-shell
pthread
recv recv
random_r random_r
send send

View File

@ -106,10 +106,19 @@ dnl Use --disable-largefile if you don't want this.
AC_SYS_LARGEFILE AC_SYS_LARGEFILE
dnl Availability of various common functions (non-fatal if missing). dnl Availability of various common functions (non-fatal if missing).
AC_CHECK_FUNCS([cfmakeraw regexec uname sched_getaffinity getuid getgid posix_fallocate mmap]) AC_CHECK_FUNCS_ONCE([cfmakeraw regexec uname sched_getaffinity getuid getgid \
posix_fallocate mmap])
dnl Availability of various not common threadsafe functions dnl Availability of various not common threadsafe functions
AC_CHECK_FUNCS([strerror_r strtok_r getmntent_r getgrnam_r getpwuid_r]) AC_CHECK_FUNCS_ONCE([strerror_r strtok_r getmntent_r getgrnam_r getpwuid_r])
dnl Availability of pthread functions (if missing, win32 threading is
dnl assumed). Because of $LIB_PTHREAD, we cannot use AC_CHECK_FUNCS_ONCE.
dnl LIB_PTHREAD was set during gl_INIT by gnulib.
old_LIBS=$LIBS
LIBS="$LIBS $LIB_PTHREAD"
AC_CHECK_FUNCS([pthread_sigmask pthread_mutexattr_init])
LIBS=$old_libs
dnl Availability of various common headers (non-fatal if missing). dnl Availability of various common headers (non-fatal if missing).
AC_CHECK_HEADERS([pwd.h paths.h regex.h sys/syslimits.h sys/utsname.h \ AC_CHECK_HEADERS([pwd.h paths.h regex.h sys/syslimits.h sys/utsname.h \
@ -137,14 +146,6 @@ AM_CONDITIONAL([HAVE_GLIBC_RPCGEN],
[test "x$ac_cv_path_RPCGEN" != "xno" && [test "x$ac_cv_path_RPCGEN" != "xno" &&
$ac_cv_path_RPCGEN -t </dev/null >/dev/null 2>&1]) $ac_cv_path_RPCGEN -t </dev/null >/dev/null 2>&1])
dnl pthread?
AC_CHECK_HEADER([pthread.h],
[AC_CHECK_LIB([pthread],[pthread_join],[
AC_DEFINE([HAVE_LIBPTHREAD],[],[Define if pthread (-lpthread)])
AC_DEFINE([HAVE_PTHREAD_H],[],[Define if <pthread.h>])
LIBS="-lpthread $LIBS"
])])
dnl Miscellaneous external programs. dnl Miscellaneous external programs.
AC_PATH_PROG([RM], [rm], [/bin/rm]) AC_PATH_PROG([RM], [rm], [/bin/rm])
AC_PATH_PROG([MV], [mv], [/bin/mv]) AC_PATH_PROG([MV], [mv], [/bin/mv])

View File

@ -984,7 +984,8 @@ libvirt_lxc_SOURCES = \
$(CPU_CONF_SOURCES) \ $(CPU_CONF_SOURCES) \
$(NWFILTER_PARAM_CONF_SOURCES) $(NWFILTER_PARAM_CONF_SOURCES)
libvirt_lxc_LDFLAGS = $(WARN_CFLAGS) $(COVERAGE_LDCFLAGS) $(CAPNG_LIBS) $(YAJL_LIBS) libvirt_lxc_LDFLAGS = $(WARN_CFLAGS) $(COVERAGE_LDCFLAGS) $(CAPNG_LIBS) $(YAJL_LIBS)
libvirt_lxc_LDADD = $(LIBXML_LIBS) $(NUMACTL_LIBS) ../gnulib/lib/libgnu.la libvirt_lxc_LDADD = $(LIBXML_LIBS) $(NUMACTL_LIBS) $(LIB_PTHREAD) \
../gnulib/lib/libgnu.la
libvirt_lxc_CFLAGS = \ libvirt_lxc_CFLAGS = \
$(LIBPARTED_CFLAGS) \ $(LIBPARTED_CFLAGS) \
$(NUMACTL_CFLAGS) \ $(NUMACTL_CFLAGS) \

View File

@ -9556,7 +9556,7 @@ remoteIOEventLoop(virConnectPtr conn,
struct remote_thread_call *tmp = priv->waitDispatch; struct remote_thread_call *tmp = priv->waitDispatch;
struct remote_thread_call *prev; struct remote_thread_call *prev;
char ignore; char ignore;
#ifdef HAVE_PTHREAD_H #ifdef HAVE_PTHREAD_SIGMASK
sigset_t oldmask, blockedsigs; sigset_t oldmask, blockedsigs;
#endif #endif
@ -9585,7 +9585,7 @@ remoteIOEventLoop(virConnectPtr conn,
* after the call (RHBZ#567931). Same for SIGCHLD and SIGPIPE * after the call (RHBZ#567931). Same for SIGCHLD and SIGPIPE
* at the suggestion of Paolo Bonzini and Daniel Berrange. * at the suggestion of Paolo Bonzini and Daniel Berrange.
*/ */
#ifdef HAVE_PTHREAD_H #ifdef HAVE_PTHREAD_SIGMASK
sigemptyset (&blockedsigs); sigemptyset (&blockedsigs);
sigaddset (&blockedsigs, SIGWINCH); sigaddset (&blockedsigs, SIGWINCH);
sigaddset (&blockedsigs, SIGCHLD); sigaddset (&blockedsigs, SIGCHLD);
@ -9598,7 +9598,7 @@ remoteIOEventLoop(virConnectPtr conn,
if (ret < 0 && errno == EAGAIN) if (ret < 0 && errno == EAGAIN)
goto repoll; goto repoll;
#ifdef HAVE_PTHREAD_H #ifdef HAVE_PTHREAD_SIGMASK
ignore_value(pthread_sigmask(SIG_SETMASK, &oldmask, NULL)); ignore_value(pthread_sigmask(SIG_SETMASK, &oldmask, NULL));
#endif #endif

View File

@ -1,7 +1,7 @@
/* /*
* threads.c: basic thread synchronization primitives * threads.c: basic thread synchronization primitives
* *
* Copyright (C) 2009 Red Hat, Inc. * Copyright (C) 2009-2010 Red Hat, Inc.
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@ -23,7 +23,7 @@
#include "threads.h" #include "threads.h"
#ifdef HAVE_PTHREAD_H #ifdef HAVE_PTHREAD_MUTEXATTR_INIT
# include "threads-pthread.c" # include "threads-pthread.c"
#else #else
# ifdef WIN32 # ifdef WIN32

View File

@ -1,7 +1,7 @@
/* /*
* threads.h: basic thread synchronization primitives * threads.h: basic thread synchronization primitives
* *
* Copyright (C) 2009 Red Hat, Inc. * Copyright (C) 2009-2010 Red Hat, Inc.
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@ -61,7 +61,7 @@ int virThreadLocalInit(virThreadLocalPtr l,
void *virThreadLocalGet(virThreadLocalPtr l); void *virThreadLocalGet(virThreadLocalPtr l);
void virThreadLocalSet(virThreadLocalPtr l, void*); void virThreadLocalSet(virThreadLocalPtr l, void*);
# ifdef HAVE_PTHREAD_H # ifdef HAVE_PTHREAD_MUTEXATTR_INIT
# include "threads-pthread.h" # include "threads-pthread.h"
# else # else
# ifdef WIN32 # ifdef WIN32

View File

@ -316,7 +316,7 @@ static int virClearCapabilities(void)
*/ */
int virFork(pid_t *pid) { int virFork(pid_t *pid) {
# ifdef HAVE_PTHREAD_H # ifdef HAVE_PTHREAD_SIGMASK
sigset_t oldmask, newmask; sigset_t oldmask, newmask;
# endif # endif
struct sigaction sig_action; struct sigaction sig_action;
@ -328,7 +328,7 @@ int virFork(pid_t *pid) {
* Need to block signals now, so that child process can safely * Need to block signals now, so that child process can safely
* kill off caller's signal handlers without a race. * kill off caller's signal handlers without a race.
*/ */
# ifdef HAVE_PTHREAD_H # ifdef HAVE_PTHREAD_SIGMASK
sigfillset(&newmask); sigfillset(&newmask);
if (pthread_sigmask(SIG_SETMASK, &newmask, &oldmask) != 0) { if (pthread_sigmask(SIG_SETMASK, &newmask, &oldmask) != 0) {
saved_errno = errno; saved_errno = errno;
@ -349,7 +349,7 @@ int virFork(pid_t *pid) {
virLogUnlock(); virLogUnlock();
if (*pid < 0) { if (*pid < 0) {
# ifdef HAVE_PTHREAD_H # ifdef HAVE_PTHREAD_SIGMASK
/* attempt to restore signal mask, but ignore failure, to /* attempt to restore signal mask, but ignore failure, to
avoid obscuring the fork failure */ avoid obscuring the fork failure */
ignore_value (pthread_sigmask(SIG_SETMASK, &oldmask, NULL)); ignore_value (pthread_sigmask(SIG_SETMASK, &oldmask, NULL));
@ -363,7 +363,7 @@ int virFork(pid_t *pid) {
/* parent process */ /* parent process */
# ifdef HAVE_PTHREAD_H # ifdef HAVE_PTHREAD_SIGMASK
/* Restore our original signal mask now that the child is /* Restore our original signal mask now that the child is
safely running */ safely running */
if (pthread_sigmask(SIG_SETMASK, &oldmask, NULL) != 0) { if (pthread_sigmask(SIG_SETMASK, &oldmask, NULL) != 0) {
@ -407,7 +407,7 @@ int virFork(pid_t *pid) {
sigaction(i, &sig_action, NULL); sigaction(i, &sig_action, NULL);
} }
# ifdef HAVE_PTHREAD_H # ifdef HAVE_PTHREAD_SIGMASK
/* Unmask all signals in child, since we've no idea /* Unmask all signals in child, since we've no idea
what the caller's done with their signal mask what the caller's done with their signal mask
and don't want to propagate that to children */ and don't want to propagate that to children */