[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Xen-devel] [PATCH 06/20] tools: Correct PTHREAD options in config/StdGNU.mk



2012/3/16 Ian Jackson <ian.jackson@xxxxxxxxxxxxx>:
> It is not correct to say -lpthread. ÂThe correct option is -pthread,
> which may have sundry other effects on code generation etc. ÂIt needs
> to be passed both to compilation and linking.
>
> Fix the configure test to test -pthread, and plumb the resulting flag
> through to PTHREAD_{CFLAGS,LDFLAGS} in Tools.mk; also substitute
> PTHREAD_LIBS (although this will currently always be empty).
> Remove PTHREAD_LIBS setting from StdGNU.mk.
>
> Fix the one user (libxc) to use PTHREAD_{CFLAGS,LDFLAGS} too.
>
> There are still some other users in tree which pass -pthread or
> -lpthread by adding it as a literal to their own compiler options.
> These will be fixed in a later patch.
>
> Signed-off-by: Ian Jackson <ian.jackson@xxxxxxxxxxxxx>
> Cc: Roger Pau Monne <roger.pau@xxxxxxxxxxxxx>
Acked-by: Roger Pau Monne <roger.pau@xxxxxxxxxxxxx>

> ---
> Âconfig/StdGNU.mk   |  Â1 -
> Âconfig/Tools.mk.in  |  Â4 ++
> Âtools/configure   Â|  95 
> +++++++++++++++++++++++++++++++++++---------------
> Âtools/configure.ac  |  Â5 ++-
> Âtools/libxc/Makefile | Â Â4 ++-
> Âtools/m4/pthread.m4 Â| Â 41 +++++++++++++++++++++
> Âtools/m4/savevar.m4 Â| Â Â6 +++
> Â7 files changed, 124 insertions(+), 32 deletions(-)
> Âcreate mode 100644 tools/m4/pthread.m4
> Âcreate mode 100644 tools/m4/savevar.m4
>

[...]

> diff --git a/tools/m4/pthread.m4 b/tools/m4/pthread.m4
> new file mode 100644
> index 0000000..57ea85c
> --- /dev/null
> +++ b/tools/m4/pthread.m4
> @@ -0,0 +1,41 @@
> +# We define, separately, PTHREAD_CFLAGS, _LDFLAGS and _LIBS
> +# even though currently we don't set them very separately.
> +# This means that the makefiles will not need to change in
> +# the future if we make the test more sophisticated.
> +
> +AC_DEFUN([AX_PTHREAD_CV2VARS],[
> + Â ÂPTHREAD_CFLAGS="$ax_cv_pthread_flags"
> + Â ÂPTHREAD_LDFLAGS="$ax_cv_pthread_flags"
> + Â ÂPTHREAD_LIBS=""
> +])
> +
> +# We invoke AX_PTHREAD_VARS with the name of another macro
> +# which is then expanded once for each variable.
> +AC_DEFUN([AX_PTHREAD_VARS],[$1(CFLAGS) $1(LDFLAGS) $1(LIBS)])
> +
> +AC_DEFUN([AX_PTHREAD_VAR_APPLY],[
> + Â Â$1="$$1 $PTHREAD_$1"
> +])
> +AC_DEFUN([AX_PTHREAD_VAR_SUBST],[AC_SUBST(PTHREAD_$1)])
> +
> +AC_DEFUN([AX_CHECK_PTHREAD],[
> + Â ÂAC_CACHE_CHECK([for pthread flag], [ax_cv_pthread_flags], [
> + Â Â Â Âax_cv_pthread_flags=-pthread
> + Â Â Â ÂAX_PTHREAD_CV2VARS
> + Â Â Â ÂAX_PTHREAD_VARS([AX_SAVEVAR_SAVE])
> + Â Â Â ÂAX_PTHREAD_VARS([AX_PTHREAD_VAR_APPLY])
> + Â Â Â ÂAC_LINK_IFELSE([
> +#include <pthread.h>
> +int main(void) {
> + Âpthread_atfork(0,0,0);
> + Âpthread_create(0,0,0,0);
> +}

You can also use something like this here, which is more autoconf style:

AC_LANG_PROGRAM([#include <pthread.h>],[
                pthread_atfork(0,0,0);
                pthread_create(0,0,0,0);])

But as is looks correct to me, I'm not a big fan of autoconf macros.

> +],[],[ax_cv_pthread_flags=failed])
> + Â Â Â ÂAX_PTHREAD_VARS([AX_SAVEVAR_RESTORE])
> + Â Â])
> + Â Âif test "x$ax_cv_pthread_flags" = xfailed; then
> + Â Â Â ÂAC_MSG_ERROR([-pthread does not work])
> + Â Âfi
> + Â ÂAX_PTHREAD_CV2VARS
> + Â ÂAX_PTHREAD_VARS([AX_PTHREAD_VAR_SUBST])
> +])
> diff --git a/tools/m4/savevar.m4 b/tools/m4/savevar.m4
> new file mode 100644
> index 0000000..2156bee
> --- /dev/null
> +++ b/tools/m4/savevar.m4
> @@ -0,0 +1,6 @@
> +AC_DEFUN([AX_SAVEVAR_SAVE],[
> + Â Âsaved_$1="$$1"
> +])
> +AC_DEFUN([AX_SAVEVAR_RESTORE],[
> + Â Â$1="$saved_$1"
> +])

This little macros will prove useful on other places, such as
python_devel.m4, that actually uses ac_previous_* to temporary store
variables.

> --
> 1.7.2.5
>

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.