]> Savannah Git Hosting - gnulib.git/commitdiff
pthread-rwlock: Port to Mac OS X 10.4.
authorBruno Haible <bruno@clisp.org>
Thu, 9 Nov 2023 02:32:20 +0000 (03:32 +0100)
committerBruno Haible <bruno@clisp.org>
Fri, 24 Nov 2023 07:22:53 +0000 (08:22 +0100)
Reported by Sevan Janiyan <venture37@geeklan.co.uk>.

* m4/pthread-rwlock.m4 (gl_PTHREAD_RWLOCK): On macOS, test for the
presence of PTHREAD_RWLOCK_INITIALIZER. If it is not defined, don't
attempt to use pthread_rwlock_init.

ChangeLog
m4/pthread-rwlock.m4

index 741dde4db833f13d14fd3384063ca3ac3f9f7e63..83db185ad87d1873b3d1b7639d0f0941e864e6c3 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2023-11-08  Bruno Haible  <bruno@clisp.org>
+
+       pthread-rwlock: Port to Mac OS X 10.4.
+       Reported by Sevan Janiyan <venture37@geeklan.co.uk>.
+       * m4/pthread-rwlock.m4 (gl_PTHREAD_RWLOCK): On macOS, test for the
+       presence of PTHREAD_RWLOCK_INITIALIZER. If it is not defined, don't
+       attempt to use pthread_rwlock_init.
+
 2023-10-24  Paul Eggert  <eggert@cs.ucla.edu>
 
        tests/unistr/u16-chr-tests: pacify -Wcast-align
index ac559e9ccef1a81b0eea93451ffc3b7bf202c571..56cc098defa2dc7df2df3580a19c7dd0021be565 100644 (file)
@@ -1,4 +1,4 @@
-# pthread-rwlock.m4 serial 2
+# pthread-rwlock.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,
@@ -38,27 +38,42 @@ AC_DEFUN([gl_PTHREAD_RWLOCK],
       HAVE_PTHREAD_RWLOCK_UNLOCK=0
       HAVE_PTHREAD_RWLOCK_DESTROY=0
     else
+      dnl On Mac OS X 10.4, the pthread_rwlock_* functions exist but are not
+      dnl usable because PTHREAD_RWLOCK_INITIALIZER is not defined.
       dnl On Android 4.3, the pthread_rwlock_* functions are declared in
       dnl <pthread.h> but don't exist in libc.
       AC_CACHE_CHECK([for pthread_rwlock_init],
         [gl_cv_func_pthread_rwlock_init],
-        [saved_LIBS="$LIBS"
-         LIBS="$LIBS $LIBPMULTITHREAD"
-         AC_LINK_IFELSE(
-           [AC_LANG_SOURCE(
-              [[extern
-                #ifdef __cplusplus
-                "C"
-                #endif
-                int pthread_rwlock_init (void);
-                int main ()
-                {
-                  return pthread_rwlock_init ();
-                }
-              ]])],
-           [gl_cv_func_pthread_rwlock_init=yes],
-           [gl_cv_func_pthread_rwlock_init=no])
-         LIBS="$saved_LIBS"
+        [case "$host_os" in
+           darwin*)
+             AC_COMPILE_IFELSE(
+               [AC_LANG_SOURCE(
+                  [[#include <pthread.h>
+                    pthread_rwlock_t l = PTHREAD_RWLOCK_INITIALIZER;
+                  ]])],
+               [gl_cv_func_pthread_rwlock_init=yes],
+               [gl_cv_func_pthread_rwlock_init=no])
+             ;;
+           *)
+             saved_LIBS="$LIBS"
+             LIBS="$LIBS $LIBPMULTITHREAD"
+             AC_LINK_IFELSE(
+               [AC_LANG_SOURCE(
+                  [[extern
+                    #ifdef __cplusplus
+                    "C"
+                    #endif
+                    int pthread_rwlock_init (void);
+                    int main ()
+                    {
+                      return pthread_rwlock_init ();
+                    }
+                  ]])],
+               [gl_cv_func_pthread_rwlock_init=yes],
+               [gl_cv_func_pthread_rwlock_init=no])
+             LIBS="$saved_LIBS"
+             ;;
+         esac
         ])
       if test $gl_cv_func_pthread_rwlock_init = no; then
         REPLACE_PTHREAD_RWLOCK_INIT=1