]> Savannah Git Hosting - gnulib.git/commitdiff
threadlib: Fix LIBMULTITHREAD on FreeBSD with --enable-threads=isoc.
authorBruno Haible <bruno@clisp.org>
Sat, 21 Dec 2019 12:53:31 +0000 (13:53 +0100)
committerBruno Haible <bruno@clisp.org>
Sat, 21 Dec 2019 12:53:31 +0000 (13:53 +0100)
* m4/threadlib.m4 (gl_STDTHREADLIB_BODY): New macro (some code moved
here from m4/threads.m4).
(gl_THREADLIB_BODY): Don't test whether mtx_lock and cnd_timedwait exist
in libc. Instead, rely on gl_STDTHREADLIB_BODY.
(gl_STDTHREADLIB): New macro.
* m4/threads.m4 (gl_THREADS_H): Require gl_STDTHREADLIB instead of
gl_THREADLIB_BODY and gl_YIELD. Don't set LIBSTDTHREAD here.

ChangeLog
m4/threadlib.m4
m4/threads.m4

index 9d3018279be93a1fd33c226f1b235b8ca2c8dca5..35cb4659dcfc4aee20bcd22c4542743e240cc022 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2019-12-21  Bruno Haible  <bruno@clisp.org>
+
+       threadlib: Fix LIBMULTITHREAD on FreeBSD with --enable-threads=isoc.
+       * m4/threadlib.m4 (gl_STDTHREADLIB_BODY): New macro (some code moved
+       here from m4/threads.m4).
+       (gl_THREADLIB_BODY): Don't test whether mtx_lock and cnd_timedwait exist
+       in libc. Instead, rely on gl_STDTHREADLIB_BODY.
+       (gl_STDTHREADLIB): New macro.
+       * m4/threads.m4 (gl_THREADS_H): Require gl_STDTHREADLIB instead of
+       gl_THREADLIB_BODY and gl_YIELD. Don't set LIBSTDTHREAD here.
+
 2019-12-21  Bruno Haible  <bruno@clisp.org>
 
        sched_yield: Don't depend on threadlib and yield.
index bf9d4e61146eb191a6e042c5f62bc45585cc22a0..48c0be6470c7bc18340b53ab5dffa2b6eb9bc857 100644 (file)
@@ -23,6 +23,15 @@ dnl multithread-safe programs.
 dnl Defines the C macro HAVE_PTHREAD_API if (at least parts of) the POSIX
 dnl threads API is available.
 
+dnl gl_STDTHREADLIB
+dnl ---------------
+dnl Tests for the libraries needs for using the ISO C threads API.
+dnl Sets the variable LIBSTDTHREAD to the linker options for use in a Makefile.
+dnl Adds to CPPFLAGS the flag -D_REENTRANT or -D_THREAD_SAFE if needed for
+dnl multithread-safe programs.
+dnl Defines the C macro HAVE_THREADS_H if (at least parts of) the ISO C threads
+dnl API is available.
+
 dnl gl_THREADLIB
 dnl ------------
 dnl Tests for a multithreading library to be used.
@@ -200,7 +209,7 @@ dnl The guts of gl_PTHREADLIB. Needs to be expanded only once.
 AC_DEFUN([gl_PTHREADLIB_BODY],
 [
   AC_REQUIRE([gl_ANYTHREADLIB_EARLY])
-  if test -z "$gl_threadlib_body_done"; then
+  if test -z "$gl_pthreadlib_body_done"; then
     gl_pthread_api=no
     LIBPTHREAD=
     LIBPMULTITHREAD=
@@ -294,7 +303,52 @@ AC_DEFUN([gl_PTHREADLIB_BODY],
       ])
     AC_SUBST([LIB_SCHED_YIELD])
 
-    gl_threadlib_body_done=done
+    gl_pthreadlib_body_done=done
+  fi
+])
+
+dnl The guts of gl_STDTHREADLIB. Needs to be expanded only once.
+
+AC_DEFUN([gl_STDTHREADLIB_BODY],
+[
+  AC_REQUIRE([gl_ANYTHREADLIB_EARLY])
+  AC_REQUIRE([AC_CANONICAL_HOST])
+  if test -z "$gl_stdthreadlib_body_done"; then
+    AC_CHECK_HEADERS_ONCE([threads.h])
+
+    case "$host_os" in
+      mingw*)
+        LIBSTDTHREAD=
+        ;;
+      *)
+        gl_PTHREADLIB_BODY
+        if test $ac_cv_header_threads_h = yes; then
+          dnl glibc >= 2.29 has thrd_create in libpthread.
+          dnl FreeBSD >= 10 has thrd_create in libstdthreads; this library depends
+          dnl on libpthread (for the symbol 'pthread_mutexattr_gettype').
+          dnl AIX >= 7.1 and Solaris >= 11.4 have thrd_create in libc.
+          AC_CHECK_FUNCS([thrd_create])
+          if test $ac_cv_func_thrd_create = yes; then
+            LIBSTDTHREAD=
+          else
+            AC_CHECK_LIB([stdthreads], [thrd_create], [
+              LIBSTDTHREAD='-lstdthreads -lpthread'
+            ], [
+              dnl Guess that thrd_create is in libpthread.
+              LIBSTDTHREAD="$LIBPMULTITHREAD"
+            ])
+          fi
+        else
+          dnl Libraries needed by thrd.c, mtx.c, cnd.c, tss.c.
+          LIBSTDTHREAD="$LIBPMULTITHREAD $LIB_SCHED_YIELD"
+        fi
+        ;;
+    esac
+    AC_SUBST([LIBSTDTHREAD])
+
+    AC_MSG_CHECKING([whether ISO C threads API is available])
+    AC_MSG_RESULT([$ac_cv_header_threads_h])
+    gl_stdthreadlib_body_done=done
   fi
 ])
 
@@ -320,20 +374,7 @@ AC_DEFUN([gl_THREADLIB_BODY],
     fi
     if test "$gl_use_threads" = isoc || test "$gl_use_threads" = isoc+posix; then
       AC_CHECK_HEADERS_ONCE([threads.h])
-      if test $ac_cv_header_threads_h = yes; then
-        gl_have_isoc_threads=
-        # Test whether both mtx_lock and cnd_timedwait exist in libc.
-        AC_LINK_IFELSE(
-          [AC_LANG_PROGRAM(
-             [[#include <threads.h>
-               #include <stddef.h>
-               mtx_t m;
-               cnd_t c;
-             ]],
-             [[mtx_lock (&m);
-               cnd_timedwait (&c, &m, NULL);]])],
-          [gl_have_isoc_threads=yes])
-      fi
+      gl_have_isoc_threads="$ac_cv_header_threads_h"
     fi
     if test "$gl_use_threads" = yes \
        || test "$gl_use_threads" = posix \
@@ -363,6 +404,9 @@ AC_DEFUN([gl_THREADLIB_BODY],
     fi
     if test $gl_threads_api = none; then
       if test "$gl_use_threads" = isoc && test "$gl_have_isoc_threads" = yes; then
+        gl_STDTHREADLIB_BODY
+        LIBTHREAD=$LIBSTDTHREAD LTLIBTHREAD=$LIBSTDTHREAD
+        LIBMULTITHREAD=$LIBSTDTHREAD LTLIBMULTITHREAD=$LIBSTDTHREAD
         gl_threads_api=isoc
         AC_DEFINE([USE_ISOC_THREADS], [1],
           [Define if the ISO C multithreading library can be used.])
@@ -398,6 +442,12 @@ AC_DEFUN([gl_PTHREADLIB],
   gl_PTHREADLIB_BODY
 ])
 
+AC_DEFUN([gl_STDTHREADLIB],
+[
+  AC_REQUIRE([gl_ANYTHREADLIB_EARLY])
+  gl_STDTHREADLIB_BODY
+])
+
 AC_DEFUN([gl_THREADLIB],
 [
   AC_REQUIRE([gl_THREADLIB_EARLY])
index f98c594977c6636d6cd13e103205187b3423f8e3..535270e0efe5c7173625fef98d1a5e4b92c5a308 100644 (file)
@@ -13,7 +13,7 @@ AC_DEFUN([gl_THREADS_H],
 [
   AC_REQUIRE([gl_THREADS_H_DEFAULTS])
   AC_REQUIRE([AC_CANONICAL_HOST])
-  AC_REQUIRE([gl_THREADLIB_BODY])
+  AC_REQUIRE([gl_STDTHREADLIB])
 
   gl_CHECK_NEXT_HEADERS([threads.h])
   if test $ac_cv_header_threads_h = yes; then
@@ -48,35 +48,6 @@ AC_DEFUN([gl_THREADS_H],
     fi
   fi
 
-  case "$host_os" in
-    mingw*)
-      LIBSTDTHREAD=
-      ;;
-    *)
-      if test $ac_cv_header_threads_h = yes; then
-        dnl glibc >= 2.29 has thrd_create in libpthread.
-        dnl FreeBSD >= 10 has thrd_create in libstdthreads; this library depends
-        dnl on libpthread (for the symbol 'pthread_mutexattr_gettype').
-        dnl AIX >= 7.1 and Solaris >= 11.4 have thrd_create in libc.
-        AC_CHECK_FUNCS([thrd_create])
-        if test $ac_cv_func_thrd_create = yes; then
-          LIBSTDTHREAD=
-        else
-          AC_CHECK_LIB([stdthreads], [thrd_create], [
-            LIBSTDTHREAD='-lstdthreads -lpthread'
-          ], [
-            dnl Guess that thrd_create is in libpthread.
-            LIBSTDTHREAD="$LIBMULTITHREAD"
-          ])
-        fi
-      else
-        dnl Libraries needed by thrd.c, mtx.c, cnd.c, tss.c.
-        LIBSTDTHREAD="$LIBMULTITHREAD $LIB_SCHED_YIELD"
-      fi
-      ;;
-  esac
-  AC_SUBST([LIBSTDTHREAD])
-
   dnl Define _Thread_local.
   dnl GCC, for example, supports '__thread' since version 3.3, but it supports
   dnl '_Thread_local' only starting with version 4.9.