mkfifoat: Work around trailing slash bug in mknodat() on AIX 7.2.
[gnulib.git] / m4 / pthread-rwlock.m4
blob0c8598bb317606136824bf4ef1ca140ea70debfa
1 # pthread-rwlock.m4 serial 2
2 dnl Copyright (C) 2019-2021 Free Software Foundation, Inc.
3 dnl This file is free software; the Free Software Foundation
4 dnl gives unlimited permission to copy and/or distribute it,
5 dnl with or without modifications, as long as this notice is preserved.
7 AC_DEFUN([gl_PTHREAD_RWLOCK],
9   AC_REQUIRE([gl_PTHREAD_H])
10   AC_REQUIRE([AC_CANONICAL_HOST])
12   if { case "$host_os" in mingw*) true;; *) false;; esac; } \
13      && test $gl_threads_api = windows; then
14     dnl Choose function names that don't conflict with the mingw-w64 winpthreads
15     dnl library.
16     REPLACE_PTHREAD_RWLOCK_INIT=1
17     REPLACE_PTHREAD_RWLOCKATTR_INIT=1
18     REPLACE_PTHREAD_RWLOCKATTR_DESTROY=1
19     REPLACE_PTHREAD_RWLOCK_RDLOCK=1
20     REPLACE_PTHREAD_RWLOCK_WRLOCK=1
21     REPLACE_PTHREAD_RWLOCK_TRYRDLOCK=1
22     REPLACE_PTHREAD_RWLOCK_TRYWRLOCK=1
23     REPLACE_PTHREAD_RWLOCK_TIMEDRDLOCK=1
24     REPLACE_PTHREAD_RWLOCK_TIMEDWRLOCK=1
25     REPLACE_PTHREAD_RWLOCK_UNLOCK=1
26     REPLACE_PTHREAD_RWLOCK_DESTROY=1
27   else
28     if test $HAVE_PTHREAD_H = 0; then
29       HAVE_PTHREAD_RWLOCK_INIT=0
30       HAVE_PTHREAD_RWLOCKATTR_INIT=0
31       HAVE_PTHREAD_RWLOCKATTR_DESTROY=0
32       HAVE_PTHREAD_RWLOCK_RDLOCK=0
33       HAVE_PTHREAD_RWLOCK_WRLOCK=0
34       HAVE_PTHREAD_RWLOCK_TRYRDLOCK=0
35       HAVE_PTHREAD_RWLOCK_TRYWRLOCK=0
36       HAVE_PTHREAD_RWLOCK_TIMEDRDLOCK=0
37       HAVE_PTHREAD_RWLOCK_TIMEDWRLOCK=0
38       HAVE_PTHREAD_RWLOCK_UNLOCK=0
39       HAVE_PTHREAD_RWLOCK_DESTROY=0
40     else
41       dnl On Android 4.3, the pthread_rwlock_* functions are declared in
42       dnl <pthread.h> but don't exist in libc.
43       AC_CACHE_CHECK([for pthread_rwlock_init],
44         [gl_cv_func_pthread_rwlock_init],
45         [saved_LIBS="$LIBS"
46          LIBS="$LIBS $LIBPMULTITHREAD"
47          AC_LINK_IFELSE(
48            [AC_LANG_SOURCE(
49               [[extern
50                 #ifdef __cplusplus
51                 "C"
52                 #endif
53                 int pthread_rwlock_init (void);
54                 int main ()
55                 {
56                   return pthread_rwlock_init ();
57                 }
58               ]])],
59            [gl_cv_func_pthread_rwlock_init=yes],
60            [gl_cv_func_pthread_rwlock_init=no])
61          LIBS="$saved_LIBS"
62         ])
63       if test $gl_cv_func_pthread_rwlock_init = no; then
64         REPLACE_PTHREAD_RWLOCK_INIT=1
65         REPLACE_PTHREAD_RWLOCKATTR_INIT=1
66         REPLACE_PTHREAD_RWLOCKATTR_DESTROY=1
67         REPLACE_PTHREAD_RWLOCK_RDLOCK=1
68         REPLACE_PTHREAD_RWLOCK_WRLOCK=1
69         REPLACE_PTHREAD_RWLOCK_TRYRDLOCK=1
70         REPLACE_PTHREAD_RWLOCK_TRYWRLOCK=1
71         REPLACE_PTHREAD_RWLOCK_TIMEDRDLOCK=1
72         REPLACE_PTHREAD_RWLOCK_TIMEDWRLOCK=1
73         REPLACE_PTHREAD_RWLOCK_UNLOCK=1
74         REPLACE_PTHREAD_RWLOCK_DESTROY=1
75         AC_DEFINE([PTHREAD_RWLOCK_UNIMPLEMENTED], [1],
76           [Define if all pthread_rwlock* functions don't exist.])
77       else
78         dnl On Mac OS X 10.5, FreeBSD 5.2.1, OpenBSD 3.8, AIX 5.1, HP-UX 11,
79         dnl IRIX 6.5, Solaris 9, Cygwin, the pthread_rwlock_timed*lock functions
80         dnl don't exist, although the other pthread_rwlock* functions exist.
81         AC_CHECK_DECL([pthread_rwlock_timedrdlock], ,
82           [HAVE_PTHREAD_RWLOCK_TIMEDRDLOCK=0
83            HAVE_PTHREAD_RWLOCK_TIMEDWRLOCK=0
84            AC_DEFINE([PTHREAD_RWLOCK_LACKS_TIMEOUT], [1],
85              [Define if the functions pthread_rwlock_timedrdlock and pthread_rwlock_timedwrlock don't exist.])
86           ],
87           [[#include <pthread.h>]])
88       fi
89     fi
90   fi