diff options
author | Bruno Haible <bruno@clisp.org> | 2005-07-25 18:55:37 +0000 |
---|---|---|
committer | Bruno Haible <bruno@clisp.org> | 2009-06-23 12:12:41 +0200 |
commit | 71d6fd8f7688853f4b75eb6fbe53cac1f58fd928 (patch) | |
tree | 2601d592e68b25384b0236b2ec37fe545a86e7ab /gettext-runtime | |
parent | 54a03935ba676145b16e7c7fc9a01ef0ffa53f65 (diff) | |
download | external_gettext-71d6fd8f7688853f4b75eb6fbe53cac1f58fd928.zip external_gettext-71d6fd8f7688853f4b75eb6fbe53cac1f58fd928.tar.gz external_gettext-71d6fd8f7688853f4b75eb6fbe53cac1f58fd928.tar.bz2 |
Fix for Solaris and HP-UX, so that pthread_in_use() returns 0 when not
linked with -lpthread.
Diffstat (limited to 'gettext-runtime')
-rw-r--r-- | gettext-runtime/intl/ChangeLog | 8 | ||||
-rw-r--r-- | gettext-runtime/intl/lock.c | 37 | ||||
-rw-r--r-- | gettext-runtime/intl/lock.h | 19 | ||||
-rw-r--r-- | gettext-runtime/m4/ChangeLog | 6 | ||||
-rw-r--r-- | gettext-runtime/m4/gettext.m4 | 1 | ||||
-rw-r--r-- | gettext-runtime/m4/lock.m4 | 15 |
6 files changed, 81 insertions, 5 deletions
diff --git a/gettext-runtime/intl/ChangeLog b/gettext-runtime/intl/ChangeLog index 3b33095..e2754c8 100644 --- a/gettext-runtime/intl/ChangeLog +++ b/gettext-runtime/intl/ChangeLog @@ -1,3 +1,11 @@ +2005-07-25 Bruno Haible <bruno@clisp.org> + + Make pthread_in_use() return 0 on Solaris and HP-UX when not linking + with -lpthread. + * lock.h (pthread_in_use) [PTHREAD_IN_USE_DETECTION_HARD]: Define + through glthread_in_use. + * lock.c (dummy_thread_func, glthread_in_use): New functions. + 2005-07-22 Bruno Haible <bruno@clisp.org> * Makefile.in (libintl.la, libgnuintl.la): Link with @LTLIBTHREADS@. diff --git a/gettext-runtime/intl/lock.c b/gettext-runtime/intl/lock.c index 5c14fa3..a860459 100644 --- a/gettext-runtime/intl/lock.c +++ b/gettext-runtime/intl/lock.c @@ -32,6 +32,43 @@ /* Use the POSIX threads library. */ +# if PTHREAD_IN_USE_DETECTION_HARD + +/* The function to be executed by a dummy thread. */ +static void * +dummy_thread_func (void *arg) +{ + return arg; +} + +int +glthread_in_use (void) +{ + static int tested; + static int result; /* 1: linked with -lpthread, 0: only with libc */ + + if (!tested) + { + pthread_t thread; + + if (pthread_create (&thread, NULL, dummy_thread_func, NULL) != 0) + /* Thread creation failed. */ + result = 0; + else + { + /* Thread creation works. */ + void *retval; + if (pthread_join (thread, &retval) != 0) + abort (); + result = 1; + } + tested = 1; + } + return result; +} + +# endif + /* -------------------------- gl_lock_t datatype -------------------------- */ /* ------------------------- gl_rwlock_t datatype ------------------------- */ diff --git a/gettext-runtime/intl/lock.h b/gettext-runtime/intl/lock.h index cdddf6c..7d2eae0 100644 --- a/gettext-runtime/intl/lock.h +++ b/gettext-runtime/intl/lock.h @@ -68,6 +68,15 @@ # include <pthread.h> # include <stdlib.h> +# if PTHREAD_IN_USE_DETECTION_HARD + +/* The pthread_in_use() detection needs to be done at runtime. */ +# define pthread_in_use() \ + glthread_in_use () +extern int glthread_in_use (void); + +# endif + # if USE_POSIX_THREADS_WEAK /* Use weak references to the POSIX threads library. */ @@ -109,12 +118,16 @@ # pragma weak pthread_self # endif -# pragma weak pthread_cancel -# define pthread_in_use() (pthread_cancel != NULL) +# if !PTHREAD_IN_USE_DETECTION_HARD +# pragma weak pthread_cancel +# define pthread_in_use() (pthread_cancel != NULL) +# endif # else -# define pthread_in_use() 1 +# if !PTHREAD_IN_USE_DETECTION_HARD +# define pthread_in_use() 1 +# endif # endif diff --git a/gettext-runtime/m4/ChangeLog b/gettext-runtime/m4/ChangeLog index 3b4e5fb..b14a65b 100644 --- a/gettext-runtime/m4/ChangeLog +++ b/gettext-runtime/m4/ChangeLog @@ -1,3 +1,9 @@ +2005-07-25 Bruno Haible <bruno@clisp.org> + + * lock.m4 (gl_LOCK): On Solaris and HP-UX, define + PTHREAD_IN_USE_DETECTION_HARD. + * gettext.m4 (AM_INTL_SUBDIR): Also hide the glthread_in_use function. + 2005-07-22 Bruno Haible <bruno@clisp.org> * lock.m4 (gl_LOCK): Stronger test for pthread functions in libc, so diff --git a/gettext-runtime/m4/gettext.m4 b/gettext-runtime/m4/gettext.m4 index b437e03..0355f73 100644 --- a/gettext-runtime/m4/gettext.m4 +++ b/gettext-runtime/m4/gettext.m4 @@ -479,6 +479,7 @@ __fsetlocking]) #define __libc_lock_init_recursive gl_recursive_lock_init #define __libc_lock_lock_recursive gl_recursive_lock_lock #define __libc_lock_unlock_recursive gl_recursive_lock_unlock +#define glthread_in_use libintl_thread_in_use #define glthread_lock_init libintl_lock_init #define glthread_lock_lock libintl_lock_lock #define glthread_lock_unlock libintl_lock_unlock diff --git a/gettext-runtime/m4/lock.m4 b/gettext-runtime/m4/lock.m4 index d7b2365..c8637a0 100644 --- a/gettext-runtime/m4/lock.m4 +++ b/gettext-runtime/m4/lock.m4 @@ -75,7 +75,17 @@ AC_HELP_STRING([--disable-threads], [build without multithread safety]), # The program links fine without libpthread. But it may actually # need to link with libpthread in order to create multiple threads. AC_CHECK_LIB(pthread, pthread_kill, - [LIBMULTITHREAD=-lpthread LTLIBMULTITHREAD=-lpthread]) + [LIBMULTITHREAD=-lpthread LTLIBMULTITHREAD=-lpthread + # On Solaris and HP-UX, most pthread functions exist also in libc. + # Therefore pthread_in_use() needs to actually try to create a + # thread: pthread_create from libc will fail, whereas + # pthread_create will actually create a thread. + case "$host_os" in + solaris* | hpux*) + AC_DEFINE([PTHREAD_IN_USE_DETECTION_HARD], 1, + [Define if the pthread_in_use() detection is hard.]) + esac + ]) else # Some library is needed. Try libpthread and libc_r. AC_CHECK_LIB(pthread, pthread_kill, @@ -239,7 +249,8 @@ dnl dnl Solaris 7,8,9 posix -lpthread Y Sol 7,8: 0.0; Sol 9: OK dnl solaris -lthread Y Sol 7,8: 0.0; Sol 9: OK dnl -dnl HP-UX 11 posix -lpthread Y OK +dnl HP-UX 11 posix -lpthread N (cc) OK +dnl Y (gcc) dnl dnl IRIX 6.5 posix -lpthread Y 0.5 dnl |