From 02d847fe9f86b0c6ff4658eb9d49fbb98c8fa69a Mon Sep 17 00:00:00 2001 From: Bruce Momjian Date: Fri, 13 Jun 2003 23:10:08 +0000 Subject: [PATCH] Add --with-threads configure option to control threaded libpq. --- configure | 76 ++++++++++++++++++++++++++++++++++-------- configure.in | 35 +++++++++++++------ doc/src/sgml/installation.sgml | 11 +++++- doc/src/sgml/libpq.sgml | 29 ++++++++-------- src/include/pg_config.h.in | 3 -- 5 files changed, 112 insertions(+), 42 deletions(-) diff --git a/configure b/configure index 35f4243436..3dd2f4dccc 100755 --- a/configure +++ b/configure @@ -855,6 +855,7 @@ Optional Packages: --with-libraries=DIRS look for additional libraries in DIRS --with-libs=DIRS alternative spelling of --with-libraries --with-pgport=PORTNUM change default port number 5432 + --with-threads allow libpq to be thread-safe --with-tcl build Tcl and Tk interfaces --without-tk do not build Tk interfaces if Tcl is enabled --with-tclconfig=DIR tclConfig.sh and tkConfig.sh are in DIR @@ -2810,6 +2811,41 @@ done IFS=$ac_save_IFS # +# Enable libpq to be thread-safe +# +echo "$as_me:$LINENO: checking allow threaded libpq" >&5 +echo $ECHO_N "checking allow threaded libpq... $ECHO_C" >&6 + + + +# Check whether --with-threads or --without-threads was given. +if test "${with_threads+set}" = set; then + withval="$with_threads" + + case $withval in + yes) + : + ;; + no) + : + ;; + *) + { { echo "$as_me:$LINENO: error: no argument expected for --with-threads option" >&5 +echo "$as_me: error: no argument expected for --with-threads option" >&2;} + { (exit 1); exit 1; }; } + ;; + esac + +else + with_threads=no + +fi; + +echo "$as_me:$LINENO: result: $with_threads" >&5 +echo "${ECHO_T}$with_threads" >&6 + + +# # Tcl/Tk # echo "$as_me:$LINENO: checking whether to build with Tcl" >&5 @@ -3550,7 +3586,7 @@ rm -f conftest* # # Pthreads # - +if test "$with_threads" = yes; then echo "$as_me:$LINENO: checking for ANSI C header files" >&5 echo $ECHO_N "checking for ANSI C header files... $ECHO_C" >&6 if test "${ac_cv_header_stdc+set}" = set; then @@ -3850,25 +3886,38 @@ echo "${ECHO_T}$ac_cv_header_pthread_h" >&6 fi if test $ac_cv_header_pthread_h = yes; then - -cat >>confdefs.h <<\_ACEOF -#define HAVE_THREADS 1 -_ACEOF - + : +else + { { echo "$as_me:$LINENO: error: pthread.h not found, required for --with-threads" >&5 +echo "$as_me: error: pthread.h not found, required for --with-threads" >&2;} + { (exit 1); exit 1; }; } fi -if test ! -z "$HAVE_THREADS" -then - case $host_os in - # BSD/OS and NetBSD require no special libraries or flags - netbsd*|bsdi*) ;; +case $host_os in + netbsd*|bsdi*) + # these require no special flags or libraries + ;; freebsd2*|freebsd3*|freebsd4*) THREAD_CFLAGS="-pthread" ;; freebsd*) THREAD_LIBS="-lc_r" ;; linux*) THREAD_LIBS="-lpthread" THREAD_CFLAGS="-D_REENTRANT" ;; - # other operating systems might fail because they have pthread.h but need - # special libs we don't know about yet. + *) + # other operating systems might fail because they have pthread.h but need + # special libs we don't know about yet. + { { echo "$as_me:$LINENO: error: +Cannot enable threads on your platform. +Please report your platform threading info to the PostgreSQL mailing lists +so it can be added to the next release. Report any compile or link flags, +or libraries required for threading support. +" >&5 +echo "$as_me: error: +Cannot enable threads on your platform. +Please report your platform threading info to the PostgreSQL mailing lists +so it can be added to the next release. Report any compile or link flags, +or libraries required for threading support. +" >&2;} + { (exit 1); exit 1; }; } esac fi @@ -17540,6 +17589,7 @@ s,@CPP@,$CPP,;t t s,@GCC@,$GCC,;t t s,@autodepend@,$autodepend,;t t s,@INCLUDES@,$INCLUDES,;t t +s,@with_threads@,$with_threads,;t t s,@with_tcl@,$with_tcl,;t t s,@with_tk@,$with_tk,;t t s,@with_perl@,$with_perl,;t t diff --git a/configure.in b/configure.in index 46647f11e1..f323dc767f 100644 --- a/configure.in +++ b/configure.in @@ -1,5 +1,5 @@ dnl Process this file with autoconf to produce a configure script. -dnl $Header: /cvsroot/pgsql/configure.in,v 1.260 2003/06/12 16:05:09 tgl Exp $ +dnl $Header: /cvsroot/pgsql/configure.in,v 1.261 2003/06/13 23:10:07 momjian Exp $ dnl dnl Developers, please strive to achieve this order: dnl @@ -320,6 +320,14 @@ done IFS=$ac_save_IFS # +# Enable libpq to be thread-safe +# +AC_MSG_CHECKING([allow threaded libpq]) +PGAC_ARG_BOOL(with, threads, no, [ --with-threads allow libpq to be thread-safe]) +AC_MSG_RESULT([$with_threads]) +AC_SUBST(with_threads) + +# # Tcl/Tk # AC_MSG_CHECKING([whether to build with Tcl]) @@ -544,20 +552,25 @@ AC_SUBST(ELF_SYS) # # Pthreads # - -AC_CHECK_HEADER(pthread.h, - [AC_DEFINE(HAVE_THREADS, 1, [Define to 1 if you have the threads interface.])]) -if test ! -z "$HAVE_THREADS" -then - case $host_os in - # BSD/OS and NetBSD require no special libraries or flags - netbsd*|bsdi*) ;; +if test "$with_threads" = yes; then +AC_CHECK_HEADER(pthread.h, [], [AC_MSG_ERROR([pthread.h not found, required for --with-threads])]) +case $host_os in + netbsd*|bsdi*) + # these require no special flags or libraries + ;; freebsd2*|freebsd3*|freebsd4*) THREAD_CFLAGS="-pthread" ;; freebsd*) THREAD_LIBS="-lc_r" ;; linux*) THREAD_LIBS="-lpthread" THREAD_CFLAGS="-D_REENTRANT" ;; - # other operating systems might fail because they have pthread.h but need - # special libs we don't know about yet. + *) + # other operating systems might fail because they have pthread.h but need + # special libs we don't know about yet. + AC_MSG_ERROR([ +Cannot enable threads on your platform. +Please report your platform threading info to the PostgreSQL mailing lists +so it can be added to the next release. Report any compile or link flags, +or libraries required for threading support. +]) esac fi AC_SUBST(THREAD_LIBS) diff --git a/doc/src/sgml/installation.sgml b/doc/src/sgml/installation.sgml index 1605199839..4c7a0a3517 100644 --- a/doc/src/sgml/installation.sgml +++ b/doc/src/sgml/installation.sgml @@ -1,4 +1,4 @@ - + <![%standalone-include[<productname>PostgreSQL</>]]> @@ -915,6 +915,15 @@ JAVACMD=$JAVA_HOME/bin/java </varlistentry> <varlistentry> + <term><option>--with-threads</option></term> + <listitem> + <para> + Allow separate libpq threads to safely control their private connection handles. + </para> + </listitem> + </varlistentry> + + <varlistentry> <term><option>--without-zlib</option></term> <listitem> <para> diff --git a/doc/src/sgml/libpq.sgml b/doc/src/sgml/libpq.sgml index 9bbf060c76..88217d4506 100644 --- a/doc/src/sgml/libpq.sgml +++ b/doc/src/sgml/libpq.sgml @@ -1,5 +1,5 @@ <!-- -$Header: /cvsroot/pgsql/doc/src/sgml/libpq.sgml,v 1.123 2003/05/14 03:25:58 tgl Exp $ +$Header: /cvsroot/pgsql/doc/src/sgml/libpq.sgml,v 1.124 2003/06/13 23:10:07 momjian Exp $ --> <chapter id="libpq"> @@ -509,11 +509,6 @@ typedef struct is leaked for each call to <function>PQconndefaults</function>. </para> - <para> - In <productname>PostgreSQL</productname> versions before 7.0, <function>PQconndefaults</function> returned a pointer - to a static array, rather than a dynamically allocated array. That - was not thread-safe, so the behavior has been changed. - </para> </listitem> </varlistentry> @@ -2549,17 +2544,23 @@ If the permissions are less strict than this, the file will be ignored. </indexterm> <para> -<application>libpq</application> is thread-safe as of -<productname>PostgreSQL</productname> 7.0, so long as no two threads -attempt to manipulate the same <structname>PGconn</> object at the same -time. In particular, you cannot issue concurrent commands from different -threads through the same connection object. (If you need to run -concurrent commands, start up multiple connections.) +<application>libpq</application> is thread-safe if the library is +compiled using the <literal>--with-threads</> +<filename>configure</filename> command-line option. (You might need to +use other threading command-line options to compile your client code.) +</para> + +<para> +One restriction is that no two threads attempt to manipulate the same +<structname>PGconn</> object at the same time. In particular, you cannot +issue concurrent commands from different threads through the same +connection object. (If you need to run concurrent commands, start up +multiple connections.) </para> <para> -<structname>PGresult</> objects are read-only after creation, and so can be passed around -freely between threads. +<structname>PGresult</> objects are read-only after creation, and so can be +passed around freely between threads. </para> <para> diff --git a/src/include/pg_config.h.in b/src/include/pg_config.h.in index a15ca6b6a6..60f9536dff 100644 --- a/src/include/pg_config.h.in +++ b/src/include/pg_config.h.in @@ -468,9 +468,6 @@ /* Define to 1 if you have the <termios.h> header file. */ #undef HAVE_TERMIOS_H -/* Define to 1 if you have the threads interface. */ -#undef HAVE_THREADS - /* Define to 1 if your `struct tm' has `tm_zone'. Deprecated, use `HAVE_STRUCT_TM_TM_ZONE' instead. */ #undef HAVE_TM_ZONE -- 2.11.0