Blame m4/threadlib.m4

Packit Service a2489d
# threadlib.m4 serial 14
Packit Service a2489d
dnl Copyright (C) 2005-2018 Free Software Foundation, Inc.
Packit Service a2489d
dnl This file is free software; the Free Software Foundation
Packit Service a2489d
dnl gives unlimited permission to copy and/or distribute it,
Packit Service a2489d
dnl with or without modifications, as long as this notice is preserved.
Packit Service a2489d
Packit Service a2489d
dnl From Bruno Haible.
Packit Service a2489d
Packit Service a2489d
dnl gl_THREADLIB
Packit Service a2489d
dnl ------------
Packit Service a2489d
dnl Tests for a multithreading library to be used.
Packit Service a2489d
dnl If the configure.ac contains a definition of the gl_THREADLIB_DEFAULT_NO
Packit Service a2489d
dnl (it must be placed before the invocation of gl_THREADLIB_EARLY!), then the
Packit Service a2489d
dnl default is 'no', otherwise it is system dependent. In both cases, the user
Packit Service a2489d
dnl can change the choice through the options --enable-threads=choice or
Packit Service a2489d
dnl --disable-threads.
Packit Service a2489d
dnl Defines at most one of the macros USE_POSIX_THREADS, USE_SOLARIS_THREADS,
Packit Service a2489d
dnl USE_PTH_THREADS, USE_WINDOWS_THREADS
Packit Service a2489d
dnl Sets the variables LIBTHREAD and LTLIBTHREAD to the linker options for use
Packit Service a2489d
dnl in a Makefile (LIBTHREAD for use without libtool, LTLIBTHREAD for use with
Packit Service a2489d
dnl libtool).
Packit Service a2489d
dnl Sets the variables LIBMULTITHREAD and LTLIBMULTITHREAD similarly, for
Packit Service a2489d
dnl programs that really need multithread functionality. The difference
Packit Service a2489d
dnl between LIBTHREAD and LIBMULTITHREAD is that on platforms supporting weak
Packit Service a2489d
dnl symbols, typically LIBTHREAD is empty whereas LIBMULTITHREAD is not.
Packit Service a2489d
dnl Adds to CPPFLAGS the flag -D_REENTRANT or -D_THREAD_SAFE if needed for
Packit Service a2489d
dnl multithread-safe programs.
Packit Service a2489d
Packit Service a2489d
AC_DEFUN([gl_THREADLIB_EARLY],
Packit Service a2489d
[
Packit Service a2489d
  AC_REQUIRE([gl_THREADLIB_EARLY_BODY])
Packit Service a2489d
])
Packit Service a2489d
Packit Service a2489d
dnl The guts of gl_THREADLIB_EARLY. Needs to be expanded only once.
Packit Service a2489d
Packit Service a2489d
AC_DEFUN([gl_THREADLIB_EARLY_BODY],
Packit Service a2489d
[
Packit Service a2489d
  dnl Ordering constraints: This macro modifies CPPFLAGS in a way that
Packit Service a2489d
  dnl influences the result of the autoconf tests that test for *_unlocked
Packit Service a2489d
  dnl declarations, on AIX 5 at least. Therefore it must come early.
Packit Service a2489d
  AC_BEFORE([$0], [gl_FUNC_GLIBC_UNLOCKED_IO])dnl
Packit Service a2489d
  AC_BEFORE([$0], [gl_ARGP])dnl
Packit Service a2489d
Packit Service a2489d
  AC_REQUIRE([AC_CANONICAL_HOST])
Packit Service a2489d
  dnl _GNU_SOURCE is needed for pthread_rwlock_t on glibc systems.
Packit Service a2489d
  dnl AC_USE_SYSTEM_EXTENSIONS was introduced in autoconf 2.60 and obsoletes
Packit Service a2489d
  dnl AC_GNU_SOURCE.
Packit Service a2489d
  m4_ifdef([AC_USE_SYSTEM_EXTENSIONS],
Packit Service a2489d
    [AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])],
Packit Service a2489d
    [AC_REQUIRE([AC_GNU_SOURCE])])
Packit Service a2489d
  dnl Check for multithreading.
Packit Service a2489d
  m4_ifdef([gl_THREADLIB_DEFAULT_NO],
Packit Service a2489d
    [m4_divert_text([DEFAULTS], [gl_use_threads_default=no])],
Packit Service a2489d
    [m4_divert_text([DEFAULTS], [gl_use_threads_default=])])
Packit Service a2489d
  AC_ARG_ENABLE([threads],
Packit Service a2489d
AC_HELP_STRING([--enable-threads={posix|solaris|pth|windows}], [specify multithreading API])m4_ifdef([gl_THREADLIB_DEFAULT_NO], [], [
Packit Service a2489d
AC_HELP_STRING([--disable-threads], [build without multithread safety])]),
Packit Service a2489d
    [gl_use_threads=$enableval],
Packit Service a2489d
    [if test -n "$gl_use_threads_default"; then
Packit Service a2489d
       gl_use_threads="$gl_use_threads_default"
Packit Service a2489d
     else
Packit Service a2489d
changequote(,)dnl
Packit Service a2489d
       case "$host_os" in
Packit Service a2489d
         dnl Disable multithreading by default on OSF/1, because it interferes
Packit Service a2489d
         dnl with fork()/exec(): When msgexec is linked with -lpthread, its
Packit Service a2489d
         dnl child process gets an endless segmentation fault inside execvp().
Packit Service a2489d
         dnl Disable multithreading by default on Cygwin 1.5.x, because it has
Packit Service a2489d
         dnl bugs that lead to endless loops or crashes. See
Packit Service a2489d
         dnl <https://cygwin.com/ml/cygwin/2009-08/msg00283.html>.
Packit Service a2489d
         osf*) gl_use_threads=no ;;
Packit Service a2489d
         cygwin*)
Packit Service a2489d
               case `uname -r` in
Packit Service a2489d
                 1.[0-5].*) gl_use_threads=no ;;
Packit Service a2489d
                 *)         gl_use_threads=yes ;;
Packit Service a2489d
               esac
Packit Service a2489d
               ;;
Packit Service a2489d
         *)    gl_use_threads=yes ;;
Packit Service a2489d
       esac
Packit Service a2489d
changequote([,])dnl
Packit Service a2489d
     fi
Packit Service a2489d
    ])
Packit Service a2489d
  if test "$gl_use_threads" = yes || test "$gl_use_threads" = posix; then
Packit Service a2489d
    # For using <pthread.h>:
Packit Service a2489d
    case "$host_os" in
Packit Service a2489d
      osf*)
Packit Service a2489d
        # On OSF/1, the compiler needs the flag -D_REENTRANT so that it
Packit Service a2489d
        # groks <pthread.h>. cc also understands the flag -pthread, but
Packit Service a2489d
        # we don't use it because 1. gcc-2.95 doesn't understand -pthread,
Packit Service a2489d
        # 2. putting a flag into CPPFLAGS that has an effect on the linker
Packit Service a2489d
        # causes the AC_LINK_IFELSE test below to succeed unexpectedly,
Packit Service a2489d
        # leading to wrong values of LIBTHREAD and LTLIBTHREAD.
Packit Service a2489d
        CPPFLAGS="$CPPFLAGS -D_REENTRANT"
Packit Service a2489d
        ;;
Packit Service a2489d
    esac
Packit Service a2489d
    # Some systems optimize for single-threaded programs by default, and
Packit Service a2489d
    # need special flags to disable these optimizations. For example, the
Packit Service a2489d
    # definition of 'errno' in <errno.h>.
Packit Service a2489d
    case "$host_os" in
Packit Service a2489d
      aix* | freebsd*) CPPFLAGS="$CPPFLAGS -D_THREAD_SAFE" ;;
Packit Service a2489d
      solaris*) CPPFLAGS="$CPPFLAGS -D_REENTRANT" ;;
Packit Service a2489d
    esac
Packit Service a2489d
  fi
Packit Service a2489d
])
Packit Service a2489d
Packit Service a2489d
dnl The guts of gl_THREADLIB. Needs to be expanded only once.
Packit Service a2489d
Packit Service a2489d
AC_DEFUN([gl_THREADLIB_BODY],
Packit Service a2489d
[
Packit Service a2489d
  AC_REQUIRE([gl_THREADLIB_EARLY_BODY])
Packit Service a2489d
  gl_threads_api=none
Packit Service a2489d
  LIBTHREAD=
Packit Service a2489d
  LTLIBTHREAD=
Packit Service a2489d
  LIBMULTITHREAD=
Packit Service a2489d
  LTLIBMULTITHREAD=
Packit Service a2489d
  if test "$gl_use_threads" != no; then
Packit Service a2489d
    dnl Check whether the compiler and linker support weak declarations.
Packit Service a2489d
    AC_CACHE_CHECK([whether imported symbols can be declared weak],
Packit Service a2489d
      [gl_cv_have_weak],
Packit Service a2489d
      [gl_cv_have_weak=no
Packit Service a2489d
       dnl First, test whether the compiler accepts it syntactically.
Packit Service a2489d
       AC_LINK_IFELSE(
Packit Service a2489d
         [AC_LANG_PROGRAM(
Packit Service a2489d
            [[extern void xyzzy ();
Packit Service a2489d
#pragma weak xyzzy]],
Packit Service a2489d
            [[xyzzy();]])],
Packit Service a2489d
         [gl_cv_have_weak=maybe])
Packit Service a2489d
       if test $gl_cv_have_weak = maybe; then
Packit Service a2489d
         dnl Second, test whether it actually works. On Cygwin 1.7.2, with
Packit Service a2489d
         dnl gcc 4.3, symbols declared weak always evaluate to the address 0.
Packit Service a2489d
         AC_RUN_IFELSE(
Packit Service a2489d
           [AC_LANG_SOURCE([[
Packit Service a2489d
#include <stdio.h>
Packit Service a2489d
#pragma weak fputs
Packit Service a2489d
int main ()
Packit Service a2489d
{
Packit Service a2489d
  return (fputs == NULL);
Packit Service a2489d
}]])],
Packit Service a2489d
           [gl_cv_have_weak=yes],
Packit Service a2489d
           [gl_cv_have_weak=no],
Packit Service a2489d
           [dnl When cross-compiling, assume that only ELF platforms support
Packit Service a2489d
            dnl weak symbols.
Packit Service a2489d
            AC_EGREP_CPP([Extensible Linking Format],
Packit Service a2489d
              [#ifdef __ELF__
Packit Service a2489d
               Extensible Linking Format
Packit Service a2489d
               #endif
Packit Service a2489d
              ],
Packit Service a2489d
              [gl_cv_have_weak="guessing yes"],
Packit Service a2489d
              [gl_cv_have_weak="guessing no"])
Packit Service a2489d
           ])
Packit Service a2489d
       fi
Packit Service a2489d
       dnl But when linking statically, weak symbols don't work.
Packit Service a2489d
       case " $LDFLAGS " in
Packit Service a2489d
         *" -static "*) gl_cv_have_weak=no ;;
Packit Service a2489d
       esac
Packit Service a2489d
      ])
Packit Service a2489d
    dnl Check whether the linker supports the --as-needed/--no-as-needed options.
Packit Service a2489d
    dnl Assume GCC, so that we can use the -Wl option.
Packit Service a2489d
    AC_CACHE_CHECK([whether the linker supports --as-needed],
Packit Service a2489d
      [gl_cv_linker_have_as_needed],
Packit Service a2489d
      [if test -n "$GCC"; then
Packit Service a2489d
         gl_saved_ldflags="$LDFLAGS"
Packit Service a2489d
         LDFLAGS="$gl_saved_ldflags -Wl,--as-needed -Wl,--no-as-needed"
Packit Service a2489d
         AC_LINK_IFELSE([AC_LANG_PROGRAM()],
Packit Service a2489d
           [gl_cv_linker_have_as_needed=yes],
Packit Service a2489d
           [gl_cv_linker_have_as_needed=no])
Packit Service a2489d
         LDFLAGS="$gl_saved_ldflags"
Packit Service a2489d
       else
Packit Service a2489d
         gl_cv_linker_have_as_needed=no
Packit Service a2489d
       fi
Packit Service a2489d
      ])
Packit Service a2489d
    dnl Check whether the linker supports the --push-state/--pop-state options.
Packit Service a2489d
    dnl Assume GCC, so that we can use the -Wl option.
Packit Service a2489d
    AC_CACHE_CHECK([whether the linker supports --push-state],
Packit Service a2489d
      [gl_cv_linker_have_push_state],
Packit Service a2489d
      [if test -n "$GCC"; then
Packit Service a2489d
         gl_saved_ldflags="$LDFLAGS"
Packit Service a2489d
         LDFLAGS="$gl_saved_ldflags -Wl,--push-state -Wl,--pop-state"
Packit Service a2489d
         AC_LINK_IFELSE([AC_LANG_PROGRAM()],
Packit Service a2489d
           [gl_cv_linker_have_push_state=yes],
Packit Service a2489d
           [gl_cv_linker_have_push_state=no])
Packit Service a2489d
         LDFLAGS="$gl_saved_ldflags"
Packit Service a2489d
       else
Packit Service a2489d
         gl_cv_linker_have_push_state=no
Packit Service a2489d
       fi
Packit Service a2489d
      ])
Packit Service a2489d
    if test "$gl_use_threads" = yes || test "$gl_use_threads" = posix; then
Packit Service a2489d
      # On OSF/1, the compiler needs the flag -pthread or -D_REENTRANT so that
Packit Service a2489d
      # it groks <pthread.h>. It's added above, in gl_THREADLIB_EARLY_BODY.
Packit Service a2489d
      AC_CHECK_HEADER([pthread.h],
Packit Service a2489d
        [gl_have_pthread_h=yes], [gl_have_pthread_h=no])
Packit Service a2489d
      if test "$gl_have_pthread_h" = yes; then
Packit Service a2489d
        # Other possible tests:
Packit Service a2489d
        #   -lpthreads (FSU threads, PCthreads)
Packit Service a2489d
        #   -lgthreads
Packit Service a2489d
        gl_have_pthread=
Packit Service a2489d
        # Test whether both pthread_mutex_lock and pthread_mutexattr_init exist
Packit Service a2489d
        # in libc. IRIX 6.5 has the first one in both libc and libpthread, but
Packit Service a2489d
        # the second one only in libpthread, and lock.c needs it.
Packit Service a2489d
        #
Packit Service a2489d
        # If -pthread works, prefer it to -lpthread, since Ubuntu 14.04
Packit Service a2489d
        # needs -pthread for some reason.  See:
Packit Service a2489d
        # https://lists.gnu.org/r/bug-gnulib/2014-09/msg00023.html
Packit Service a2489d
        save_LIBS=$LIBS
Packit Service a2489d
        for gl_pthread in '' '-pthread'; do
Packit Service a2489d
          LIBS="$LIBS $gl_pthread"
Packit Service a2489d
          AC_LINK_IFELSE(
Packit Service a2489d
            [AC_LANG_PROGRAM(
Packit Service a2489d
               [[#include <pthread.h>
Packit Service a2489d
                 pthread_mutex_t m;
Packit Service a2489d
                 pthread_mutexattr_t ma;
Packit Service a2489d
               ]],
Packit Service a2489d
               [[pthread_mutex_lock (&m);
Packit Service a2489d
                 pthread_mutexattr_init (&ma);]])],
Packit Service a2489d
            [gl_have_pthread=yes
Packit Service a2489d
             LIBTHREAD=$gl_pthread LTLIBTHREAD=$gl_pthread
Packit Service a2489d
             LIBMULTITHREAD=$gl_pthread LTLIBMULTITHREAD=$gl_pthread])
Packit Service a2489d
          LIBS=$save_LIBS
Packit Service a2489d
          test -n "$gl_have_pthread" && break
Packit Service a2489d
        done
Packit Service a2489d
Packit Service a2489d
        # Test for libpthread by looking for pthread_kill. (Not pthread_self,
Packit Service a2489d
        # since it is defined as a macro on OSF/1.)
Packit Service a2489d
        if test -n "$gl_have_pthread" && test -z "$LIBTHREAD"; then
Packit Service a2489d
          # The program links fine without libpthread. But it may actually
Packit Service a2489d
          # need to link with libpthread in order to create multiple threads.
Packit Service a2489d
          AC_CHECK_LIB([pthread], [pthread_kill],
Packit Service a2489d
            [LIBMULTITHREAD=-lpthread LTLIBMULTITHREAD=-lpthread
Packit Service a2489d
             # On Solaris and HP-UX, most pthread functions exist also in libc.
Packit Service a2489d
             # Therefore pthread_in_use() needs to actually try to create a
Packit Service a2489d
             # thread: pthread_create from libc will fail, whereas
Packit Service a2489d
             # pthread_create will actually create a thread.
Packit Service a2489d
             # On Solaris 10 or newer, this test is no longer needed, because
Packit Service a2489d
             # libc contains the fully functional pthread functions.
Packit Service a2489d
             case "$host_os" in
Packit Service a2489d
               solaris | solaris2.[1-9] | solaris2.[1-9].* | hpux*)
Packit Service a2489d
                 AC_DEFINE([PTHREAD_IN_USE_DETECTION_HARD], [1],
Packit Service a2489d
                   [Define if the pthread_in_use() detection is hard.])
Packit Service a2489d
             esac
Packit Service a2489d
            ])
Packit Service a2489d
        elif test -z "$gl_have_pthread"; then
Packit Service a2489d
          # Some library is needed. Try libpthread and libc_r.
Packit Service a2489d
          AC_CHECK_LIB([pthread], [pthread_kill],
Packit Service a2489d
            [gl_have_pthread=yes
Packit Service a2489d
             LIBTHREAD=-lpthread LTLIBTHREAD=-lpthread
Packit Service a2489d
             LIBMULTITHREAD=-lpthread LTLIBMULTITHREAD=-lpthread])
Packit Service a2489d
          if test -z "$gl_have_pthread"; then
Packit Service a2489d
            # For FreeBSD 4.
Packit Service a2489d
            AC_CHECK_LIB([c_r], [pthread_kill],
Packit Service a2489d
              [gl_have_pthread=yes
Packit Service a2489d
               LIBTHREAD=-lc_r LTLIBTHREAD=-lc_r
Packit Service a2489d
               LIBMULTITHREAD=-lc_r LTLIBMULTITHREAD=-lc_r])
Packit Service a2489d
          fi
Packit Service a2489d
        fi
Packit Service a2489d
        if test -n "$gl_have_pthread"; then
Packit Service a2489d
          gl_threads_api=posix
Packit Service a2489d
          AC_DEFINE([USE_POSIX_THREADS], [1],
Packit Service a2489d
            [Define if the POSIX multithreading library can be used.])
Packit Service a2489d
          if test -n "$LIBMULTITHREAD" || test -n "$LTLIBMULTITHREAD"; then
Packit Service a2489d
            if case "$gl_cv_have_weak" in *yes) true;; *) false;; esac; then
Packit Service a2489d
              AC_DEFINE([USE_POSIX_THREADS_WEAK], [1],
Packit Service a2489d
                [Define if references to the POSIX multithreading library should be made weak.])
Packit Service a2489d
              LIBTHREAD=
Packit Service a2489d
              LTLIBTHREAD=
Packit Service a2489d
              dnl On platforms where GCC enables --as-needed by default, attempt
Packit Service a2489d
              dnl to make sure that LIBMULTITHREAD really links with -lpthread.
Packit Service a2489d
              dnl Otherwise linking with LIBMULTITHREAD has no effect; then
Packit Service a2489d
              dnl the weak symbols are not defined and thus evaluate to NULL.
Packit Service a2489d
              case "$LIBMULTITHREAD" in
Packit Service a2489d
                "") ;;
Packit Service a2489d
                -pthread)
Packit Service a2489d
                  if test $gl_cv_linker_have_as_needed = yes; then
Packit Service a2489d
                    if test $gl_cv_linker_have_push_state = yes; then
Packit Service a2489d
                      LIBMULTITHREAD="$LIBMULTITHREAD -Wl,--push-state -Wl,--no-as-needed -lpthread -Wl,--pop-state"
Packit Service a2489d
                    else
Packit Service a2489d
                      LIBMULTITHREAD="$LIBMULTITHREAD -Wl,--no-as-needed -lpthread"
Packit Service a2489d
                    fi
Packit Service a2489d
                  fi
Packit Service a2489d
                  ;;
Packit Service a2489d
                *)
Packit Service a2489d
                  if test $gl_cv_linker_have_as_needed = yes; then
Packit Service a2489d
                    if test $gl_cv_linker_have_push_state = yes; then
Packit Service a2489d
                      LIBMULTITHREAD="-Wl,--push-state -Wl,--no-as-needed $LIBMULTITHREAD -Wl,--pop-state"
Packit Service a2489d
                    else
Packit Service a2489d
                      LIBMULTITHREAD="-Wl,--no-as-needed $LIBMULTITHREAD"
Packit Service a2489d
                    fi
Packit Service a2489d
                  fi
Packit Service a2489d
                  ;;
Packit Service a2489d
              esac
Packit Service a2489d
              # TODO: May need to modify LTLIBMULTITHREAD similarly.
Packit Service a2489d
            fi
Packit Service a2489d
          fi
Packit Service a2489d
        fi
Packit Service a2489d
      fi
Packit Service a2489d
    fi
Packit Service a2489d
    if test -z "$gl_have_pthread"; then
Packit Service a2489d
      if test "$gl_use_threads" = yes || test "$gl_use_threads" = solaris; then
Packit Service a2489d
        gl_have_solaristhread=
Packit Service a2489d
        gl_save_LIBS="$LIBS"
Packit Service a2489d
        LIBS="$LIBS -lthread"
Packit Service a2489d
        AC_LINK_IFELSE(
Packit Service a2489d
          [AC_LANG_PROGRAM(
Packit Service a2489d
             [[
Packit Service a2489d
#include <thread.h>
Packit Service a2489d
#include <synch.h>
Packit Service a2489d
             ]],
Packit Service a2489d
             [[thr_self();]])],
Packit Service a2489d
          [gl_have_solaristhread=yes])
Packit Service a2489d
        LIBS="$gl_save_LIBS"
Packit Service a2489d
        if test -n "$gl_have_solaristhread"; then
Packit Service a2489d
          gl_threads_api=solaris
Packit Service a2489d
          LIBTHREAD=-lthread
Packit Service a2489d
          LTLIBTHREAD=-lthread
Packit Service a2489d
          LIBMULTITHREAD="$LIBTHREAD"
Packit Service a2489d
          LTLIBMULTITHREAD="$LTLIBTHREAD"
Packit Service a2489d
          AC_DEFINE([USE_SOLARIS_THREADS], [1],
Packit Service a2489d
            [Define if the old Solaris multithreading library can be used.])
Packit Service a2489d
          if case "$gl_cv_have_weak" in *yes) true;; *) false;; esac; then
Packit Service a2489d
            AC_DEFINE([USE_SOLARIS_THREADS_WEAK], [1],
Packit Service a2489d
              [Define if references to the old Solaris multithreading library should be made weak.])
Packit Service a2489d
            LIBTHREAD=
Packit Service a2489d
            LTLIBTHREAD=
Packit Service a2489d
            dnl On platforms where GCC enables --as-needed by default, attempt
Packit Service a2489d
            dnl to make sure that LIBMULTITHREAD really links with -lthread.
Packit Service a2489d
            dnl Otherwise linking with LIBMULTITHREAD has no effect; then
Packit Service a2489d
            dnl the weak symbols are not defined and thus evaluate to NULL.
Packit Service a2489d
            if test $gl_cv_linker_have_as_needed = yes; then
Packit Service a2489d
              if test $gl_cv_linker_have_push_state = yes; then
Packit Service a2489d
                LIBMULTITHREAD="-Wl,--push-state -Wl,--no-as-needed $LIBMULTITHREAD -Wl,--pop-state"
Packit Service a2489d
              else
Packit Service a2489d
                LIBMULTITHREAD="-Wl,--no-as-needed $LIBMULTITHREAD"
Packit Service a2489d
              fi
Packit Service a2489d
            fi
Packit Service a2489d
            # TODO: May need to modify LTLIBMULTITHREAD similarly.
Packit Service a2489d
          fi
Packit Service a2489d
        fi
Packit Service a2489d
      fi
Packit Service a2489d
    fi
Packit Service a2489d
    if test "$gl_use_threads" = pth; then
Packit Service a2489d
      gl_save_CPPFLAGS="$CPPFLAGS"
Packit Service a2489d
      AC_LIB_LINKFLAGS([pth])
Packit Service a2489d
      gl_have_pth=
Packit Service a2489d
      gl_save_LIBS="$LIBS"
Packit Service a2489d
      LIBS="$LIBS $LIBPTH"
Packit Service a2489d
      AC_LINK_IFELSE(
Packit Service a2489d
        [AC_LANG_PROGRAM([[#include <pth.h>]], [[pth_self();]])],
Packit Service a2489d
        [gl_have_pth=yes])
Packit Service a2489d
      LIBS="$gl_save_LIBS"
Packit Service a2489d
      if test -n "$gl_have_pth"; then
Packit Service a2489d
        gl_threads_api=pth
Packit Service a2489d
        LIBTHREAD="$LIBPTH"
Packit Service a2489d
        LTLIBTHREAD="$LTLIBPTH"
Packit Service a2489d
        LIBMULTITHREAD="$LIBTHREAD"
Packit Service a2489d
        LTLIBMULTITHREAD="$LTLIBTHREAD"
Packit Service a2489d
        AC_DEFINE([USE_PTH_THREADS], [1],
Packit Service a2489d
          [Define if the GNU Pth multithreading library can be used.])
Packit Service a2489d
        if test -n "$LIBMULTITHREAD" || test -n "$LTLIBMULTITHREAD"; then
Packit Service a2489d
          if case "$gl_cv_have_weak" in *yes) true;; *) false;; esac; then
Packit Service a2489d
            AC_DEFINE([USE_PTH_THREADS_WEAK], [1],
Packit Service a2489d
              [Define if references to the GNU Pth multithreading library should be made weak.])
Packit Service a2489d
            LIBTHREAD=
Packit Service a2489d
            LTLIBTHREAD=
Packit Service a2489d
            dnl On platforms where GCC enables --as-needed by default, attempt
Packit Service a2489d
            dnl to make sure that LIBMULTITHREAD really links with -lpth.
Packit Service a2489d
            dnl Otherwise linking with LIBMULTITHREAD has no effect; then
Packit Service a2489d
            dnl the weak symbols are not defined and thus evaluate to NULL.
Packit Service a2489d
            if test $gl_cv_linker_have_as_needed = yes; then
Packit Service a2489d
              if test $gl_cv_linker_have_push_state = yes; then
Packit Service a2489d
                LIBMULTITHREAD="-Wl,--push-state -Wl,--no-as-needed $LIBMULTITHREAD -Wl,--pop-state"
Packit Service a2489d
              else
Packit Service a2489d
                LIBMULTITHREAD="-Wl,--no-as-needed $LIBMULTITHREAD"
Packit Service a2489d
              fi
Packit Service a2489d
            fi
Packit Service a2489d
            # TODO: May need to modify LTLIBMULTITHREAD similarly.
Packit Service a2489d
          fi
Packit Service a2489d
        fi
Packit Service a2489d
      else
Packit Service a2489d
        CPPFLAGS="$gl_save_CPPFLAGS"
Packit Service a2489d
      fi
Packit Service a2489d
    fi
Packit Service a2489d
    if test -z "$gl_have_pthread"; then
Packit Service a2489d
      case "$gl_use_threads" in
Packit Service a2489d
        yes | windows | win32) # The 'win32' is for backward compatibility.
Packit Service a2489d
          if { case "$host_os" in
Packit Service a2489d
                 mingw*) true;;
Packit Service a2489d
                 *) false;;
Packit Service a2489d
               esac
Packit Service a2489d
             }; then
Packit Service a2489d
            gl_threads_api=windows
Packit Service a2489d
            AC_DEFINE([USE_WINDOWS_THREADS], [1],
Packit Service a2489d
              [Define if the native Windows multithreading API can be used.])
Packit Service a2489d
          fi
Packit Service a2489d
          ;;
Packit Service a2489d
      esac
Packit Service a2489d
    fi
Packit Service a2489d
  fi
Packit Service a2489d
  AC_MSG_CHECKING([for multithread API to use])
Packit Service a2489d
  AC_MSG_RESULT([$gl_threads_api])
Packit Service a2489d
  AC_SUBST([LIBTHREAD])
Packit Service a2489d
  AC_SUBST([LTLIBTHREAD])
Packit Service a2489d
  AC_SUBST([LIBMULTITHREAD])
Packit Service a2489d
  AC_SUBST([LTLIBMULTITHREAD])
Packit Service a2489d
])
Packit Service a2489d
Packit Service a2489d
AC_DEFUN([gl_THREADLIB],
Packit Service a2489d
[
Packit Service a2489d
  AC_REQUIRE([gl_THREADLIB_EARLY])
Packit Service a2489d
  AC_REQUIRE([gl_THREADLIB_BODY])
Packit Service a2489d
])
Packit Service a2489d
Packit Service a2489d
Packit Service a2489d
dnl gl_DISABLE_THREADS
Packit Service a2489d
dnl ------------------
Packit Service a2489d
dnl Sets the gl_THREADLIB default so that threads are not used by default.
Packit Service a2489d
dnl The user can still override it at installation time, by using the
Packit Service a2489d
dnl configure option '--enable-threads'.
Packit Service a2489d
Packit Service a2489d
AC_DEFUN([gl_DISABLE_THREADS], [
Packit Service a2489d
  m4_divert_text([INIT_PREPARE], [gl_use_threads_default=no])
Packit Service a2489d
])
Packit Service a2489d
Packit Service a2489d
Packit Service a2489d
dnl Survey of platforms:
Packit Service a2489d
dnl
Packit Service a2489d
dnl Platform           Available  Compiler    Supports   test-lock
Packit Service a2489d
dnl                    flavours   option      weak       result
Packit Service a2489d
dnl ---------------    ---------  ---------   --------   ---------
Packit Service a2489d
dnl Linux 2.4/glibc    posix      -lpthread       Y      OK
Packit Service a2489d
dnl
Packit Service a2489d
dnl GNU Hurd/glibc     posix
Packit Service a2489d
dnl
Packit Service a2489d
dnl Ubuntu 14.04       posix      -pthread        Y      OK
Packit Service a2489d
dnl
Packit Service a2489d
dnl FreeBSD 5.3        posix      -lc_r           Y
Packit Service a2489d
dnl                    posix      -lkse ?         Y
Packit Service a2489d
dnl                    posix      -lpthread ?     Y
Packit Service a2489d
dnl                    posix      -lthr           Y
Packit Service a2489d
dnl
Packit Service a2489d
dnl FreeBSD 5.2        posix      -lc_r           Y
Packit Service a2489d
dnl                    posix      -lkse           Y
Packit Service a2489d
dnl                    posix      -lthr           Y
Packit Service a2489d
dnl
Packit Service a2489d
dnl FreeBSD 4.0,4.10   posix      -lc_r           Y      OK
Packit Service a2489d
dnl
Packit Service a2489d
dnl NetBSD 1.6         --
Packit Service a2489d
dnl
Packit Service a2489d
dnl OpenBSD 3.4        posix      -lpthread       Y      OK
Packit Service a2489d
dnl
Packit Service a2489d
dnl Mac OS X 10.[123]  posix      -lpthread       Y      OK
Packit Service a2489d
dnl
Packit Service a2489d
dnl Solaris 7,8,9      posix      -lpthread       Y      Sol 7,8: 0.0; Sol 9: OK
Packit Service a2489d
dnl                    solaris    -lthread        Y      Sol 7,8: 0.0; Sol 9: OK
Packit Service a2489d
dnl
Packit Service a2489d
dnl HP-UX 11           posix      -lpthread       N (cc) OK
Packit Service a2489d
dnl                                               Y (gcc)
Packit Service a2489d
dnl
Packit Service a2489d
dnl IRIX 6.5           posix      -lpthread       Y      0.5
Packit Service a2489d
dnl
Packit Service a2489d
dnl AIX 4.3,5.1        posix      -lpthread       N      AIX 4: 0.5; AIX 5: OK
Packit Service a2489d
dnl
Packit Service a2489d
dnl OSF/1 4.0,5.1      posix      -pthread (cc)   N      OK
Packit Service a2489d
dnl                               -lpthread (gcc) Y
Packit Service a2489d
dnl
Packit Service a2489d
dnl Cygwin             posix      -lpthread       Y      OK
Packit Service a2489d
dnl
Packit Service a2489d
dnl Any of the above   pth        -lpth                  0.0
Packit Service a2489d
dnl
Packit Service a2489d
dnl Mingw              windows                    N      OK
Packit Service a2489d
dnl
Packit Service a2489d
dnl BeOS 5             --
Packit Service a2489d
dnl
Packit Service a2489d
dnl The test-lock result shows what happens if in test-lock.c EXPLICIT_YIELD is
Packit Service a2489d
dnl turned off:
Packit Service a2489d
dnl   OK if all three tests terminate OK,
Packit Service a2489d
dnl   0.5 if the first test terminates OK but the second one loops endlessly,
Packit Service a2489d
dnl   0.0 if the first test already loops endlessly.