From 802f913fcc00f4a0afbaf9a64c41a5d7b4f49ec6 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Thu, 9 Nov 2023 03:32:20 +0100 Subject: [PATCH] pthread-rwlock: Port to Mac OS X 10.4. Reported by Sevan Janiyan . * 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 | 8 +++++++ m4/pthread-rwlock.m4 | 51 ++++++++++++++++++++++++++++---------------- 2 files changed, 41 insertions(+), 18 deletions(-) diff --git a/ChangeLog b/ChangeLog index 741dde4db8..83db185ad8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2023-11-08 Bruno Haible + + pthread-rwlock: Port to Mac OS X 10.4. + Reported by Sevan Janiyan . + * 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 tests/unistr/u16-chr-tests: pacify -Wcast-align diff --git a/m4/pthread-rwlock.m4 b/m4/pthread-rwlock.m4 index ac559e9cce..56cc098def 100644 --- a/m4/pthread-rwlock.m4 +++ b/m4/pthread-rwlock.m4 @@ -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 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_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 -- 2.39.5