]> Savannah Git Hosting - gnulib.git/commitdiff
pthread-h: Fix override of pthread_spinlock_t with non-GNU compilers.
authorBruno Haible <bruno@clisp.org>
Thu, 28 Mar 2024 21:05:39 +0000 (22:05 +0100)
committerBruno Haible <bruno@clisp.org>
Thu, 28 Mar 2024 21:05:39 +0000 (22:05 +0100)
* m4/pthread-spin.m4 (gl_PTHREAD_SPIN): Define through AC_DEFUN_ONCE.
Require gl_PTHREAD_H_DEFAULTS, not gl_PTHREAD_H.
* m4/pthread_h.m4 (gl_PTHREAD_H): Invoke gl_PTHREAD_SPIN.
* lib/pthread.in.h (pthread_spinlock_t,
GNULIB_defined_pthread_spin_types): Don't define if
HAVE_PTHREAD_SPIN_INIT && !REPLACE_PTHREAD_SPIN_INIT.
* modules/pthread-h (Files): Add m4/pthread-spin.m4.

ChangeLog
lib/pthread.in.h
m4/pthread-spin.m4
m4/pthread_h.m4
modules/pthread-h

index 797dd77c6254cb15bb7942f62f9cb351d346aadc..79167a7f51883add2615b185f1b06d592511b4b1 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2024-03-28  Bruno Haible  <bruno@clisp.org>
+
+       pthread-h: Fix override of pthread_spinlock_t with non-GNU compilers.
+       * m4/pthread-spin.m4 (gl_PTHREAD_SPIN): Define through AC_DEFUN_ONCE.
+       Require gl_PTHREAD_H_DEFAULTS, not gl_PTHREAD_H.
+       * m4/pthread_h.m4 (gl_PTHREAD_H): Invoke gl_PTHREAD_SPIN.
+       * lib/pthread.in.h (pthread_spinlock_t,
+       GNULIB_defined_pthread_spin_types): Don't define if
+       HAVE_PTHREAD_SPIN_INIT && !REPLACE_PTHREAD_SPIN_INIT.
+       * modules/pthread-h (Files): Add m4/pthread-spin.m4.
+
 2024-03-28  Bruno Haible  <bruno@clisp.org>
 
        havelib: Recognize ELF platform despite SunPRO C on Linux.
index cd705fbd18a97d6f2881e7787ed0e085c3da7069..81598616df5ae7eb0a342c344e908191c1c8dca8 100644 (file)
@@ -417,16 +417,21 @@ typedef pthread_mutex_t pthread_spinlock_t;
 #else
 # if @HAVE_PTHREAD_SPINLOCK_T@
 /* <pthread.h> exists and defines pthread_spinlock_t.  */
-#  if !(((__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 7) \
-          || __clang_major__ > 3 || (__clang_major__ == 3 && __clang_minor__ >= 1)) \
-         || (((__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 1)) \
-              && !defined __ANDROID__) \
-             || __clang_major__ >= 3)) \
-        && !defined __ibmxl__)
+#  if !@HAVE_PTHREAD_SPIN_INIT@ || @REPLACE_PTHREAD_SPIN_INIT@
+/* If the 'pthread-spin' module is in use, it defines all the pthread_spin*
+   functions.  Prepare for it by overriding pthread_spinlock_t if that might
+   be needed.  */
+#   if !(((__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 7) \
+           || __clang_major__ > 3 || (__clang_major__ == 3 && __clang_minor__ >= 1)) \
+          || (((__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 1)) \
+               && !defined __ANDROID__) \
+              || __clang_major__ >= 3)) \
+         && !defined __ibmxl__)
 /* We can't use GCC built-ins.  Approximate spinlocks with mutexes.  */
-#   if !GNULIB_defined_pthread_spin_types
-#    define pthread_spinlock_t pthread_mutex_t
-#    define GNULIB_defined_pthread_spin_types 1
+#    if !GNULIB_defined_pthread_spin_types
+#     define pthread_spinlock_t pthread_mutex_t
+#     define GNULIB_defined_pthread_spin_types 1
+#    endif
 #   endif
 #  endif
 # else
index 05c38ba3cc2b557f248fb2cf666086a73e8edff5..deb463774dc047ce719a1af61667145c2b64a0b3 100644 (file)
@@ -1,12 +1,12 @@
-# pthread-spin.m4 serial 6
+# pthread-spin.m4 serial 7
 dnl Copyright (C) 2019-2024 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
 dnl with or without modifications, as long as this notice is preserved.
 
-AC_DEFUN([gl_PTHREAD_SPIN],
+AC_DEFUN_ONCE([gl_PTHREAD_SPIN],
 [
-  AC_REQUIRE([gl_PTHREAD_H])
+  AC_REQUIRE([gl_PTHREAD_H_DEFAULTS])
   AC_REQUIRE([AC_CANONICAL_HOST])
 
   if { case "$host_os" in mingw* | windows*) true;; *) false;; esac; } \
index c33afa0ce27ff3de5b868915988a5b7de0a57c8a..9954c81c171dabf4511b5da71f3f6f299ee0cd6a 100644 (file)
@@ -1,4 +1,4 @@
-# pthread_h.m4 serial 9
+# pthread_h.m4 serial 10
 dnl Copyright (C) 2009-2024 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -41,6 +41,8 @@ AC_DEFUN_ONCE([gl_PTHREAD_H],
   if test $ac_cv_type_pthread_spinlock_t != yes; then
     HAVE_PTHREAD_SPINLOCK_T=0
   fi
+  dnl Set HAVE_PTHREAD_SPIN_INIT, REPLACE_PTHREAD_SPIN_INIT.
+  gl_PTHREAD_SPIN
 
   dnl Constants may be defined as C preprocessor macros or as enum items.
 
index 6daa6d02a70c8fad7fe6250a4bd75ad2ba01609c..241671404c19cfb2fc60b7fcc716507cc2e88be3 100644 (file)
@@ -5,6 +5,7 @@ Files:
 lib/pthread.in.h
 m4/pthread_h.m4
 m4/threadlib.m4
+m4/pthread-spin.m4
 
 Depends-on:
 extensions