Blame m4/threadlib.m4

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