From: Bruno Haible Date: Mon, 25 Jul 2005 18:55:37 +0000 (+0000) Subject: Fix for Solaris and HP-UX, so that pthread_in_use() returns 0 when not X-Git-Tag: v0.15~462 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=71d6fd8f7688853f4b75eb6fbe53cac1f58fd928;p=thirdparty%2Fgettext.git Fix for Solaris and HP-UX, so that pthread_in_use() returns 0 when not linked with -lpthread. --- diff --git a/gettext-runtime/intl/ChangeLog b/gettext-runtime/intl/ChangeLog index 3b33095ba..e2754c814 100644 --- a/gettext-runtime/intl/ChangeLog +++ b/gettext-runtime/intl/ChangeLog @@ -1,3 +1,11 @@ +2005-07-25 Bruno Haible + + 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 * Makefile.in (libintl.la, libgnuintl.la): Link with @LTLIBTHREADS@. diff --git a/gettext-runtime/intl/lock.c b/gettext-runtime/intl/lock.c index 5c14fa3a3..a860459d1 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 cdddf6cd4..7d2eae0d0 100644 --- a/gettext-runtime/intl/lock.h +++ b/gettext-runtime/intl/lock.h @@ -68,6 +68,15 @@ # include # include +# 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 3b4e5fb14..b14a65bdf 100644 --- a/gettext-runtime/m4/ChangeLog +++ b/gettext-runtime/m4/ChangeLog @@ -1,3 +1,9 @@ +2005-07-25 Bruno Haible + + * 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 * 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 b437e03cb..0355f737a 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 d7b2365f3..c8637a031 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