]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
Fix for Solaris and HP-UX, so that pthread_in_use() returns 0 when not
authorBruno Haible <bruno@clisp.org>
Mon, 25 Jul 2005 18:55:37 +0000 (18:55 +0000)
committerBruno Haible <bruno@clisp.org>
Tue, 23 Jun 2009 10:12:41 +0000 (12:12 +0200)
linked with -lpthread.

gettext-runtime/intl/ChangeLog
gettext-runtime/intl/lock.c
gettext-runtime/intl/lock.h
gettext-runtime/m4/ChangeLog
gettext-runtime/m4/gettext.m4
gettext-runtime/m4/lock.m4

index 3b33095ba7d0bf3ec8ce3bbe909677a43dfa6398..e2754c814eb10dcdc82601f021cb7205986820ea 100644 (file)
@@ -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@.
index 5c14fa3a3ef85c59d993166a065d75a64df1d800..a860459d12153ab23017ce64ddebd293e081311c 100644 (file)
 
 /* 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 ------------------------- */
index cdddf6cd43dd2ed6a685ca811129e5c1c7a8f0a3..7d2eae0d06b7485b3668c5d33b1c0105adb128ae 100644 (file)
 # 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.  */
 #   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
 
index 3b4e5fb1465cbb0c6ae9f9427179382196ceeb22..b14a65bdf50d743b7b561ca057531170d5c07581 100644 (file)
@@ -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
index b437e03cb7f6813e9c1626677a3493c5fd8fb8b6..0355f737a5f05887d464f181f08e26e73230a99a 100644 (file)
@@ -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
index d7b2365f34bd7c11ed35b96180c7eaa6f1177013..c8637a031072cd37b0c7bc245449d0a5587365bc 100644 (file)
@@ -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