1
# lock.m4 serial 2 (gettext-0.15)
2
dnl Copyright (C) 2005 Free Software Foundation, Inc.
1
# lock.m4 serial 6 (gettext-0.16)
2
dnl Copyright (C) 2005-2006 Free Software Foundation, Inc.
3
3
dnl This file is free software; the Free Software Foundation
4
4
dnl gives unlimited permission to copy and/or distribute it,
5
5
dnl with or without modifications, as long as this notice is preserved.
19
19
dnl Adds to CPPFLAGS the flag -D_REENTRANT or -D_THREAD_SAFE if needed for
20
20
dnl multithread-safe programs.
22
AC_DEFUN([gl_LOCK_EARLY],
24
AC_REQUIRE([gl_LOCK_BODY])
24
AC_REQUIRE([gl_LOCK_EARLY_BODY])
27
dnl The guts of gl_LOCK. Needs to be expanded only once.
27
dnl The guts of gl_LOCK_EARLY. Needs to be expanded only once.
29
AC_DEFUN([gl_LOCK_BODY],
29
AC_DEFUN([gl_LOCK_EARLY_BODY],
31
31
dnl Ordering constraints: This macro modifies CPPFLAGS in a way that
32
32
dnl influences the result of the autoconf tests that test for *_unlocked
40
40
AC_ARG_ENABLE(threads,
41
41
AC_HELP_STRING([--enable-threads={posix|solaris|pth|win32}], [specify multithreading API])
42
42
AC_HELP_STRING([--disable-threads], [build without multithread safety]),
43
gl_use_threads=$enableval, gl_use_threads=yes)
43
[gl_use_threads=$enableval],
45
dnl Disable multithreading by default on OSF/1, because it interferes
46
dnl with fork()/exec(): When msgexec is linked with -lpthread, its child
47
dnl process gets an endless segmentation fault inside execvp().
48
osf*) gl_use_threads=no ;;
49
*) gl_use_threads=yes ;;
52
if test "$gl_use_threads" = yes || test "$gl_use_threads" = posix; then
53
# For using <pthread.h>:
56
# On OSF/1, the compiler needs the flag -D_REENTRANT so that it
57
# groks <pthread.h>. cc also understands the flag -pthread, but
58
# we don't use it because 1. gcc-2.95 doesn't understand -pthread,
59
# 2. putting a flag into CPPFLAGS that has an effect on the linker
60
# causes the AC_TRY_LINK test below to succeed unexpectedly,
61
# leading to wrong values of LIBTHREAD and LTLIBTHREAD.
62
CPPFLAGS="$CPPFLAGS -D_REENTRANT"
65
# Some systems optimize for single-threaded programs by default, and
66
# need special flags to disable these optimizations. For example, the
67
# definition of 'errno' in <errno.h>.
69
aix* | freebsd*) CPPFLAGS="$CPPFLAGS -D_THREAD_SAFE" ;;
70
solaris*) CPPFLAGS="$CPPFLAGS -D_REENTRANT" ;;
75
dnl The guts of gl_LOCK. Needs to be expanded only once.
77
AC_DEFUN([gl_LOCK_BODY],
79
AC_REQUIRE([gl_LOCK_EARLY_BODY])
44
80
gl_threads_api=none
55
91
AC_MSG_RESULT([$gl_have_weak])
56
92
if test "$gl_use_threads" = yes || test "$gl_use_threads" = posix; then
57
93
# On OSF/1, the compiler needs the flag -pthread or -D_REENTRANT so that
58
# it groks <pthread.h>.
59
gl_save_CPPFLAGS="$CPPFLAGS"
60
CPPFLAGS="$CPPFLAGS -D_REENTRANT"
94
# it groks <pthread.h>. It's added above, in gl_LOCK_EARLY_BODY.
61
95
AC_CHECK_HEADER(pthread.h, gl_have_pthread_h=yes, gl_have_pthread_h=no)
62
CPPFLAGS="$gl_save_CPPFLAGS"
63
96
if test "$gl_have_pthread_h" = yes; then
64
97
# Other possible tests:
65
98
# -lpthreads (FSU threads, PCthreads)
69
# On OSF/1, the compiler needs the flag -D_REENTRANT so that it
70
# groks <pthread.h>. cc also understands the flag -pthread, but
71
# we don't use it because 1. gcc-2.95 doesn't understand -pthread,
72
# 2. putting a flag into CPPFLAGS that has an effect on the linker
73
# causes the AC_TRY_LINK test below to succeed unexpectedly,
74
# leading to wrong values of LIBTHREAD and LTLIBTHREAD.
75
CPPFLAGS="$CPPFLAGS -D_REENTRANT"
79
101
# Test whether both pthread_mutex_lock and pthread_mutexattr_init exist
80
102
# in libc. IRIX 6.5 has the first one in both libc and libpthread, but
139
161
error "No, in FreeBSD 4.0 recursive mutexes actually don't work."
141
163
int x = (int)PTHREAD_MUTEX_RECURSIVE;
143
166
[AC_DEFINE([HAVE_PTHREAD_MUTEX_RECURSIVE], 1,
144
167
[Define if the <pthread.h> defines PTHREAD_MUTEX_RECURSIVE.])])
145
# Some systems optimize for single-threaded programs by default, and
146
# need special flags to disable these optimizations. For example, the
147
# definition of 'errno' in <errno.h>.
149
aix* | freebsd*) CPPFLAGS="$CPPFLAGS -D_THREAD_SAFE" ;;
150
solaris*) CPPFLAGS="$CPPFLAGS -D_REENTRANT" ;;