[patch 03/15] pthread.patch

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Gary V. Vaughan
Date: Monday, March 15, 2010 - 10:42 pm

Without this patch, systems that provide stubs for pthread functions
in libc, but which still require libpthread for full the pthread
implementation are not detected correctly.

Also, some systems require -pthread in CFLAGS for each compilation
unit for a successful link of an mt binary, which is also addressed by
this patch.
---
 Makefile      |    4 ++++
 config.mak.in |    1 +
 configure.ac  |   17 +++++++++++++++--
 3 files changed, 20 insertions(+), 2 deletions(-)

Index: b/Makefile
===================================================================
--- a/Makefile
+++ b/Makefile
@@ -287,6 +287,7 @@ RPMBUILD = rpmbuild
 TCL_PATH = tclsh
 TCLTK_PATH = wish
 PTHREAD_LIBS = -lpthread
+PTHREAD_CFLAGS =
 
 export TCL_PATH TCLTK_PATH
 
@@ -856,6 +857,8 @@ ifeq ($(uname_S),AIX)
 	BASIC_CFLAGS += -D_LARGE_FILES
 	ifeq ($(shell expr "$(uname_V)" : '[1234]'),1)
 		NO_PTHREADS = YesPlease
+	else
+		PTHREAD_LIBS = -lpthread
 	endif
 endif
 ifeq ($(uname_S),GNU)
@@ -1297,6 +1300,7 @@ endif
 ifdef NO_PTHREADS
 	BASIC_CFLAGS += -DNO_PTHREADS
 else
+	BASIC_CFLAGS += $(PTHREAD_CFLAGS)
 	EXTLIBS += $(PTHREAD_LIBS)
 	LIB_OBJS += thread-utils.o
 endif
Index: b/configure.ac
===================================================================
--- a/configure.ac
+++ b/configure.ac
@@ -782,7 +782,11 @@ AC_DEFUN([PTHREADTEST_SRC], [
 int main(void)
 {
 	pthread_mutex_t test_mutex;
-	return (0);
+	int retcode = 0;
+	retcode |= pthread_mutex_init(&test_mutex,(void*)0);
+	retcode |= pthread_mutex_lock(&test_mutex);
+	retcode |= pthread_mutex_unlock(&test_mutex);
+	return retcode;
 }
 ])
 
@@ -799,7 +803,8 @@ if test -n "$USER_NOPTHREAD"; then
 # handle these separately since PTHREAD_CFLAGS could be '-lpthreads
 # -D_REENTRANT' or some such.
 elif test -z "$PTHREAD_CFLAGS"; then
-  for opt in -pthread -lpthread; do
+  threads_found=no
+  for opt in -mt -pthread -lpthread; do
      old_CFLAGS="$CFLAGS"
      CFLAGS="$opt $CFLAGS"
      AC_MSG_CHECKING([Checking for POSIX Threads with '$opt'])
@@ -807,11 +812,18 @@ elif test -z "$PTHREAD_CFLAGS"; then
 	[AC_MSG_RESULT([yes])
 		NO_PTHREADS=
 		PTHREAD_LIBS="$opt"
+		PTHREAD_CFLAGS="$opt"
+		threads_found=yes
 		break
 	],
 	[AC_MSG_RESULT([no])])
       CFLAGS="$old_CFLAGS"
   done
+  if test $threads_found != yes; then
+    AC_CHECK_LIB([pthread], [pthread_create],
+	[PTHREAD_LIBS="-lpthread"],
+	[NO_PTHREADS=UnfortunatelyYes])
+  fi
 else
   old_CFLAGS="$CFLAGS"
   CFLAGS="$PTHREAD_CFLAGS $CFLAGS"
@@ -828,6 +840,7 @@ fi
 
 CFLAGS="$old_CFLAGS"
 
+AC_SUBST(PTHREAD_CFLAGS)
 AC_SUBST(PTHREAD_LIBS)
 AC_SUBST(NO_PTHREADS)
 
Index: b/config.mak.in
===================================================================
--- a/config.mak.in
+++ b/config.mak.in
@@ -57,4 +57,5 @@ NO_DEFLATE_BOUND=@NO_DEFLATE_BOUND@
 FREAD_READS_DIRECTORIES=@FREAD_READS_DIRECTORIES@
 SNPRINTF_RETURNS_BOGUS=@SNPRINTF_RETURNS_BOGUS@
 NO_PTHREADS=@NO_PTHREADS@
+PTHREAD_CFLAGS=@PTHREAD_CFLAGS@
 PTHREAD_LIBS=@PTHREAD_LIBS@

-- 
Gary V. Vaughan (gary@thewrittenword.com)
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[patch 00/15] Portability Patches v3, Gary V. Vaughan, (Mon Mar 15, 10:42 pm)
[patch 02/15] const-expr.patch, Gary V. Vaughan, (Mon Mar 15, 10:42 pm)
[patch 03/15] pthread.patch, Gary V. Vaughan, (Mon Mar 15, 10:42 pm)
[patch 04/15] diff-export.patch, Gary V. Vaughan, (Mon Mar 15, 10:42 pm)
[patch 05/15] diff-test_cmp.patch, Gary V. Vaughan, (Mon Mar 15, 10:42 pm)
[patch 06/15] diff-defaults.patch, Gary V. Vaughan, (Mon Mar 15, 10:42 pm)
[patch 07/15] host-IRIX.patch, Gary V. Vaughan, (Mon Mar 15, 10:42 pm)
[patch 08/15] host-HPUX10.patch, Gary V. Vaughan, (Mon Mar 15, 10:42 pm)
[patch 10/15] host-OSF1.patch, Gary V. Vaughan, (Mon Mar 15, 10:42 pm)
[patch 11/15] no-hstrerror.patch, Gary V. Vaughan, (Mon Mar 15, 10:42 pm)
[patch 12/15] no-inet_ntop.patch, Gary V. Vaughan, (Mon Mar 15, 10:42 pm)
[patch 13/15] no-socklen_t.patch, Gary V. Vaughan, (Mon Mar 15, 10:42 pm)
[patch 14/15] no-ss_family.patch, Gary V. Vaughan, (Mon Mar 15, 10:42 pm)
[patch 15/15] no-inline.patch, Gary V. Vaughan, (Mon Mar 15, 10:42 pm)
Re: [patch 00/15] Portability Patches v3, Sverre Rabbelier, (Mon Mar 15, 11:18 pm)
Re: [patch 05/15] diff-test_cmp.patch, Junio C Hamano, (Tue Mar 16, 12:21 am)
Re: [patch 03/15] pthread.patch, Junio C Hamano, (Tue Mar 16, 12:21 am)
Re: [patch 06/15] diff-defaults.patch, Junio C Hamano, (Tue Mar 16, 12:22 am)
Re: [patch 07/15] host-IRIX.patch, Junio C Hamano, (Tue Mar 16, 12:24 am)
Re: [patch 11/15] no-hstrerror.patch, Junio C Hamano, (Tue Mar 16, 12:24 am)
Re: [patch 04/15] diff-export.patch, Junio C Hamano, (Tue Mar 16, 12:24 am)
Re: [patch 13/15] no-socklen_t.patch, Junio C Hamano, (Tue Mar 16, 12:25 am)
Re: [patch 02/15] const-expr.patch, Johannes Sixt, (Tue Mar 16, 12:31 am)
Re: [patch 02/15] const-expr.patch, Gary V. Vaughan, (Tue Mar 16, 1:23 am)
Re: [patch 07/15] host-IRIX.patch, Brandon Casey, (Tue Mar 16, 8:27 am)
Re: [patch 00/15] Portability Patches v3, Brandon Casey, (Tue Mar 16, 9:03 am)
Re: [patch 02/15] const-expr.patch, Avery Pennarun, (Tue Mar 16, 4:43 pm)
Re: [patch 02/15] const-expr.patch, Gary V. Vaughan, (Sun Apr 25, 1:38 am)
Re: [patch 05/15] diff-test_cmp.patch, Gary V. Vaughan, (Sun Apr 25, 1:38 am)
Re: [patch 06/15] diff-defaults.patch, Gary V. Vaughan, (Sun Apr 25, 1:38 am)
Re: [patch 07/15] host-IRIX.patch, Gary V. Vaughan, (Sun Apr 25, 1:39 am)
Re: [patch 07/15] host-IRIX.patch, Gary V. Vaughan, (Sun Apr 25, 1:39 am)
Re: [patch 11/15] no-hstrerror.patch, Gary V. Vaughan, (Sun Apr 25, 1:39 am)
Re: [patch 13/15] no-socklen_t.patch, Gary V. Vaughan, (Sun Apr 25, 1:39 am)