]> Savannah Git Hosting - gnulib.git/commitdiff
pthread-spin: Fix link errors on FreeBSD 5.2.1/i386.
authorBruno Haible <bruno@clisp.org>
Sun, 15 Oct 2023 20:00:04 +0000 (22:00 +0200)
committerBruno Haible <bruno@clisp.org>
Sun, 5 Nov 2023 19:18:18 +0000 (20:18 +0100)
* m4/pthread-spin.m4 (gl_PTHREAD_SPIN): Test not only whether
<pthread.h> defines the pthread_spinlock_t type, but also whether the
function pthread_spin_init is actually defined.

ChangeLog
m4/pthread-spin.m4

index 2b6e326d99f673637af244c2d1e0e198f2e2ae8b..f8de19c3cd74a61c1e83ba804800ac45859857eb 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2023-10-15  Bruno Haible  <bruno@clisp.org>
+
+       pthread-spin: Fix link errors on FreeBSD 5.2.1/i386.
+       * m4/pthread-spin.m4 (gl_PTHREAD_SPIN): Test not only whether
+       <pthread.h> defines the pthread_spinlock_t type, but also whether the
+       function pthread_spin_init is actually defined.
+
 2023-10-15  Bruno Haible  <bruno@clisp.org>
 
        pthread_mutex_timedlock: Fix link errors on FreeBSD 5.2.1/i386.
index d64bb682fb5e6e40cd502e7435636f49752dd348..09bb4996823a8bf12b54fd5d48c47e22b0a5d5de 100644 (file)
@@ -1,4 +1,4 @@
-# pthread-spin.m4 serial 2
+# pthread-spin.m4 serial 2.1
 dnl Copyright (C) 2019-2023 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -25,6 +25,41 @@ AC_DEFUN([gl_PTHREAD_SPIN],
       HAVE_PTHREAD_SPIN_TRYLOCK=0
       HAVE_PTHREAD_SPIN_UNLOCK=0
       HAVE_PTHREAD_SPIN_DESTROY=0
+    else
+      dnl Test whether the gnulib module 'threadlib' is in use.
+      dnl Some packages like Emacs use --avoid=threadlib.
+      dnl Write the symbol in such a way that it does not cause 'aclocal' to pick
+      dnl the threadlib.m4 file that is installed in $PREFIX/share/aclocal/.
+      m4_ifdef([gl_][THREADLIB], [
+        AC_REQUIRE([gl_][THREADLIB])
+        dnl Test whether the functions actually exist.
+        dnl FreeBSD 5.2.1 declares them but does not define them.
+        AC_CACHE_CHECK([for pthread_spin_init],
+          [gl_cv_func_pthread_spin_init_in_LIBMULTITHREAD],
+          [gl_save_LIBS="$LIBS"
+           LIBS="$LIBS $LIBMULTITHREAD"
+           AC_LINK_IFELSE(
+             [AC_LANG_PROGRAM(
+                [[#include <pthread.h>
+                ]],
+                [[pthread_spinlock_t *lock;
+                  return pthread_spin_init (&lock, 0);
+                ]])
+             ],
+             [gl_cv_func_pthread_spin_init_in_LIBMULTITHREAD=yes],
+             [gl_cv_func_pthread_spin_init_in_LIBMULTITHREAD=no])
+           LIBS="$gl_save_LIBS"
+          ])
+        if test $gl_cv_func_pthread_spin_init_in_LIBMULTITHREAD != yes; then
+          HAVE_PTHREAD_SPIN_INIT=0
+          HAVE_PTHREAD_SPIN_LOCK=0
+          HAVE_PTHREAD_SPIN_TRYLOCK=0
+          HAVE_PTHREAD_SPIN_UNLOCK=0
+          HAVE_PTHREAD_SPIN_DESTROY=0
+        fi
+      ], [
+        :
+      ])
     fi
   fi
 ])