threads / patch / 16156

patchAdd autoconf tests for pthreads

Subject: [PATCH] Add autoconf tests for pthreads

## tl;dr

2 messages between Nov 3, 2008 and Nov 3, 2008. Diffs are folded; open one to read it.

replies: 1people: 2as markdown or json

david.syzdek@acsalaska.net· Nov 3, 2008, 18:14 UTC · lore
From: David M. Syzdek <david.syzdek@acsalaska.net>

Sets the value of PTHREAD_LIBS to the correct flags for linking pthreads on the current environment. If the correct flags can be determined then THREADED_DELTA_SEARCH is set. If the correct flags cannot be determined, then THREADED_DELTA_SEARCH is unset.

Signed-off-by: David M. Syzdek <david.syzdek@acsalaska.net>
---
 config.mak.in |    2 ++
 configure.ac  |   20 ++++++++++++++++++++
 2 files changed, 22 insertions(+), 0 deletions(-)
Show changes to 2 files +22 −0

config.mak.in, configure.ac

diff --git a/config.mak.in b/config.mak.in
index 7170729..3d3fbcd 100644
--- a/config.mak.in
+++ b/config.mak.in
@@ -51,3 +51,5 @@ OLD_ICONV=@OLD_ICONV@
 NO_DEFLATE_BOUND=@NO_DEFLATE_BOUND@
 FREAD_READS_DIRECTORIES=@FREAD_READS_DIRECTORIES@
 SNPRINTF_RETURNS_BOGUS=@SNPRINTF_RETURNS_BOGUS@
+THREADED_DELTA_SEARCH=@THREADED_DELTA_SEARCH@
+PTHREAD_LIBS=@PTHREAD_LIBS@
diff --git a/configure.ac b/configure.ac
index 9dfc0d3..3bf5d15 100644
--- a/configure.ac
+++ b/configure.ac
@@ -489,6 +489,26 @@ AC_SUBST(NO_MKDTEMP)
 #
 # Define NO_SYMLINK_HEAD if you never want .git/HEAD to be a symbolic link.
 # Enable it on Windows.  By default, symrefs are still used.
+#
+# Define PTHREAD_LIBS to the linker flag used for Pthread support and define
+# THREADED_DELTA_SEARCH if Pthreads are available.
+AC_LANG_CONFTEST([AC_LANG_PROGRAM(
+  [[#include <pthread.h>]],
+  [[pthread_mutex_t test_mutex;]]
+)])
+${CC} -pthread conftest.c -o conftest.o > /dev/null 2>&1
+if test $? -eq 0;then
+ PTHREAD_LIBS="-pthread"
+ THREADED_DELTA_SEARCH=YesPlease
+else
+ ${CC} -lpthread conftest.c -o conftest.o > /dev/null 2>&1
+ if test $? -eq 0;then
+  PTHREAD_LIBS="-lpthread"
+  THREADED_DELTA_SEARCH=YesPlease
+ fi
+fi
+AC_SUBST(PTHREAD_LIBS)
+AC_SUBST(THREADED_DELTA_SEARCH)
 
 ## Site configuration (override autodetection)
 ## --with-PACKAGE[=ARG] and --without-PACKAGE
-- 
1.6.0.2.GIT
Junio C Hamano· Nov 3, 2008, 22:07 UTC · re: david.syzdek@acsalaska.net · lore

Re: [PATCH] Add autoconf tests for pthreads

david.syzdek@acsalaska.net writes:
> +# Define PTHREAD_LIBS to the linker flag used for Pthread support and define
> +# THREADED_DELTA_SEARCH if Pthreads are available.

This may affect platforms that do have pthread library but choose not to use threaded delta search for whatever reason by suddenly turning it on.

Which arguably may be a good thing to do, but it is a change unrelated to porting to FreeBSD.

Show 10 quoted lines
> +AC_LANG_CONFTEST([AC_LANG_PROGRAM(
> +  [[#include <pthread.h>]],
> +  [[pthread_mutex_t test_mutex;]]
> +)])
> +${CC} -pthread conftest.c -o conftest.o > /dev/null 2>&1
> +if test $? -eq 0;then
> + PTHREAD_LIBS="-pthread"
> + THREADED_DELTA_SEARCH=YesPlease
> +else
> + ${CC} -lpthread conftest.c -o conftest.o > /dev/null 2>&1

Maybe I am old fashioned, but having "-library" very near the beginning of the command line and naming the final link product (i.e. not with -c) *.o makes me go "Huh?" If it were written like this,

	$CC -o conftest$ac_exeext conftest.c -lpthread
it might have been easier to swallow.  I dunno.

← back to recent threads