Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 62b532b

Browse files
committed
Add thread.c for libpq threading, and hook it into libpq/configure.
1 parent 02d847f commit 62b532b

File tree

8 files changed

+259
-20
lines changed

8 files changed

+259
-20
lines changed

configure

+105-6
Original file line numberDiff line numberDiff line change
@@ -2824,7 +2824,11 @@ if test "${with_threads+set}" = set; then
28242824
28252825
case $withval in
28262826
yes)
2827-
:
2827+
2828+
cat >>confdefs.h <<\_ACEOF
2829+
#define USE_THREADS 1
2830+
_ACEOF
2831+
28282832
;;
28292833
no)
28302834
:
@@ -2841,6 +2845,7 @@ else
28412845
28422846
fi;
28432847
2848+
28442849
echo "$as_me:$LINENO: result: $with_threads" >&5
28452850
echo "${ECHO_T}$with_threads" >&6
28462851
@@ -3899,9 +3904,12 @@ case $host_os in
38993904
# these require no special flags or libraries
39003905
;;
39013906
freebsd2*|freebsd3*|freebsd4*) THREAD_CFLAGS="-pthread" ;;
3902-
freebsd*) THREAD_LIBS="-lc_r" ;;
3903-
linux*) THREAD_LIBS="-lpthread"
3904-
THREAD_CFLAGS="-D_REENTRANT" ;;
3907+
freebsd*)
3908+
THREAD_LIBS="-lc_r"
3909+
;;
3910+
linux*) THREAD_CFLAGS="-D_REENTRANT -D_THREAD_SAFE -D_POSIX_PTHREAD_SEMANTICS"
3911+
THREAD_LIBS="-lpthread"
3912+
;;
39053913
*)
39063914
# other operating systems might fail because they have pthread.h but need
39073915
# special libs we don't know about yet.
@@ -3918,7 +3926,7 @@ so it can be added to the next release. Report any compile or link flags,
39183926
or libraries required for threading support.
39193927
" >&2;}
39203928
{ (exit 1); exit 1; }; }
3921-
esac
3929+
esac
39223930
fi
39233931
39243932
@@ -12818,6 +12826,97 @@ _ACEOF
1281812826
fi
1281912827
1282012828
12829+
#
12830+
# Check for re-entrant versions of certain functions
12831+
#
12832+
# Include special flags if required
12833+
#
12834+
_CFLAGS="$CFLAGS"
12835+
_LIB="$LIBS"
12836+
CFLAGS="$CFLAGS $TREAD_CFLAGS"
12837+
LIBS="$LIBS $THREAD_LIBS"
12838+
12839+
12840+
12841+
for ac_func in strerror_r getpwuid_r gethostbyname_r
12842+
do
12843+
as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh`
12844+
echo "$as_me:$LINENO: checking for $ac_func" >&5
12845+
echo $ECHO_N "checking for $ac_func... $ECHO_C" >&6
12846+
if eval "test \"\${$as_ac_var+set}\" = set"; then
12847+
echo $ECHO_N "(cached) $ECHO_C" >&6
12848+
else
12849+
cat >conftest.$ac_ext <<_ACEOF
12850+
#line $LINENO "configure"
12851+
#include "confdefs.h"
12852+
/* System header to define __stub macros and hopefully few prototypes,
12853+
which can conflict with char $ac_func (); below. */
12854+
#include <assert.h>
12855+
/* Override any gcc2 internal prototype to avoid an error. */
12856+
#ifdef __cplusplus
12857+
extern "C"
12858+
#endif
12859+
/* We use char because int might match the return type of a gcc2
12860+
builtin and then its argument prototype would still apply. */
12861+
char $ac_func ();
12862+
char (*f) ();
12863+
12864+
#ifdef F77_DUMMY_MAIN
12865+
# ifdef __cplusplus
12866+
extern "C"
12867+
# endif
12868+
int F77_DUMMY_MAIN() { return 1; }
12869+
#endif
12870+
int
12871+
main ()
12872+
{
12873+
/* The GNU C library defines this for functions which it implements
12874+
to always fail with ENOSYS. Some functions are actually named
12875+
something starting with __ and the normal name is an alias. */
12876+
#if defined (__stub_$ac_func) || defined (__stub___$ac_func)
12877+
choke me
12878+
#else
12879+
f = $ac_func;
12880+
#endif
12881+
12882+
;
12883+
return 0;
12884+
}
12885+
_ACEOF
12886+
rm -f conftest.$ac_objext conftest$ac_exeext
12887+
if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
12888+
(eval $ac_link) 2>&5
12889+
ac_status=$?
12890+
echo "$as_me:$LINENO: \$? = $ac_status" >&5
12891+
(exit $ac_status); } &&
12892+
{ ac_try='test -s conftest$ac_exeext'
12893+
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
12894+
(eval $ac_try) 2>&5
12895+
ac_status=$?
12896+
echo "$as_me:$LINENO: \$? = $ac_status" >&5
12897+
(exit $ac_status); }; }; then
12898+
eval "$as_ac_var=yes"
12899+
else
12900+
echo "$as_me: failed program was:" >&5
12901+
cat conftest.$ac_ext >&5
12902+
eval "$as_ac_var=no"
12903+
fi
12904+
rm -f conftest.$ac_objext conftest$ac_exeext conftest.$ac_ext
12905+
fi
12906+
echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_var'}'`" >&5
12907+
echo "${ECHO_T}`eval echo '${'$as_ac_var'}'`" >&6
12908+
if test `eval echo '${'$as_ac_var'}'` = yes; then
12909+
cat >>confdefs.h <<_ACEOF
12910+
#define `echo "HAVE_$ac_func" | $as_tr_cpp` 1
12911+
_ACEOF
12912+
12913+
fi
12914+
done
12915+
12916+
CFLAGS="$_CFLAGS"
12917+
LIB="$_LIBS"
12918+
12919+
1282112920
1282212921
# This test makes sure that run tests work at all. Sometimes a shared
1282312922
# library is found by the linker, but the runtime linker can't find it.
@@ -17603,8 +17702,8 @@ s,@with_pam@,$with_pam,;t t
1760317702
s,@with_rendezvous@,$with_rendezvous,;t t
1760417703
s,@with_openssl@,$with_openssl,;t t
1760517704
s,@ELF_SYS@,$ELF_SYS,;t t
17606-
s,@THREAD_LIBS@,$THREAD_LIBS,;t t
1760717705
s,@THREAD_CFLAGS@,$THREAD_CFLAGS,;t t
17706+
s,@THREAD_LIBS@,$THREAD_LIBS,;t t
1760817707
s,@AWK@,$AWK,;t t
1760917708
s,@FLEX@,$FLEX,;t t
1761017709
s,@FLEXFLAGS@,$FLEXFLAGS,;t t

configure.in

+26-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
dnl Process this file with autoconf to produce a configure script.
2-
dnl $Header: /cvsroot/pgsql/configure.in,v 1.261 2003/06/13 23:10:07 momjian Exp $
2+
dnl $Header: /cvsroot/pgsql/configure.in,v 1.262 2003/06/14 14:35:42 momjian Exp $
33
dnl
44
dnl Developers, please strive to achieve this order:
55
dnl
@@ -323,7 +323,9 @@ IFS=$ac_save_IFS
323323
# Enable libpq to be thread-safe
324324
#
325325
AC_MSG_CHECKING([allow threaded libpq])
326-
PGAC_ARG_BOOL(with, threads, no, [ --with-threads allow libpq to be thread-safe])
326+
PGAC_ARG_BOOL(with, threads, no, [ --with-threads allow libpq to be thread-safe],
327+
[AC_DEFINE([USE_THREADS], 1, [Define to 1 to build libpq with threads. (--with-threads)])])
328+
327329
AC_MSG_RESULT([$with_threads])
328330
AC_SUBST(with_threads)
329331

@@ -559,9 +561,12 @@ case $host_os in
559561
# these require no special flags or libraries
560562
;;
561563
freebsd2*|freebsd3*|freebsd4*) THREAD_CFLAGS="-pthread" ;;
562-
freebsd*) THREAD_LIBS="-lc_r" ;;
563-
linux*) THREAD_LIBS="-lpthread"
564-
THREAD_CFLAGS="-D_REENTRANT" ;;
564+
freebsd*)
565+
THREAD_LIBS="-lc_r"
566+
;;
567+
linux*) THREAD_CFLAGS="-D_REENTRANT -D_THREAD_SAFE -D_POSIX_PTHREAD_SEMANTICS"
568+
THREAD_LIBS="-lpthread"
569+
;;
565570
*)
566571
# other operating systems might fail because they have pthread.h but need
567572
# special libs we don't know about yet.
@@ -571,10 +576,10 @@ Please report your platform threading info to the PostgreSQL mailing lists
571576
so it can be added to the next release. Report any compile or link flags,
572577
or libraries required for threading support.
573578
])
574-
esac
579+
esac
575580
fi
576-
AC_SUBST(THREAD_LIBS)
577581
AC_SUBST(THREAD_CFLAGS)
582+
AC_SUBST(THREAD_LIBS)
578583

579584
#
580585
# Assignments
@@ -983,6 +988,20 @@ AC_CHECK_FUNCS(atexit, [],
983988

984989
AC_FUNC_FSEEKO
985990

991+
#
992+
# Check for re-entrant versions of certain functions
993+
#
994+
# Include special flags if required
995+
#
996+
_CFLAGS="$CFLAGS"
997+
_LIB="$LIBS"
998+
CFLAGS="$CFLAGS $TREAD_CFLAGS"
999+
LIBS="$LIBS $THREAD_LIBS"
1000+
AC_CHECK_FUNCS([strerror_r getpwuid_r gethostbyname_r])
1001+
CFLAGS="$_CFLAGS"
1002+
LIB="$_LIBS"
1003+
1004+
9861005

9871006
# This test makes sure that run tests work at all. Sometimes a shared
9881007
# library is found by the linker, but the runtime linker can't find it.

src/Makefile.global.in

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# -*-makefile-*-
2-
# $Header: /cvsroot/pgsql/src/Makefile.global.in,v 1.163 2003/05/27 16:36:50 momjian Exp $
2+
# $Header: /cvsroot/pgsql/src/Makefile.global.in,v 1.164 2003/06/14 14:35:42 momjian Exp $
33

44
#------------------------------------------------------------------------------
55
# All PostgreSQL makefiles include this file and use the variables it sets,
@@ -121,6 +121,7 @@ localedir := @localedir@
121121
#
122122
# Records the choice of the various --enable-xxx and --with-xxx options.
123123

124+
with_threads = @with_threads@
124125
with_java = @with_java@
125126
with_perl = @with_perl@
126127
with_python = @with_python@
@@ -340,7 +341,7 @@ endif
340341
#
341342
# substitute implementations of the C library
342343

343-
LIBOBJS = @LIBOBJS@ path.o
344+
LIBOBJS = @LIBOBJS@ path.o threads.o
344345

345346
ifneq (,$(LIBOBJS))
346347
LIBS += -lpgport

src/include/pg_config.h.in

+12
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,9 @@
121121
/* Define to 1 if you have the `getaddrinfo' function. */
122122
#undef HAVE_GETADDRINFO
123123

124+
/* Define to 1 if you have the `gethostbyname_r' function. */
125+
#undef HAVE_GETHOSTBYNAME_R
126+
124127
/* Define to 1 if you have the `gethostname' function. */
125128
#undef HAVE_GETHOSTNAME
126129

@@ -136,6 +139,9 @@
136139
/* Define to 1 if you have the `getpeereid' function. */
137140
#undef HAVE_GETPEEREID
138141

142+
/* Define to 1 if you have the `getpwuid_r' function. */
143+
#undef HAVE_GETPWUID_R
144+
139145
/* Define to 1 if you have the `getrusage' function. */
140146
#undef HAVE_GETRUSAGE
141147

@@ -375,6 +381,9 @@
375381
/* Define to 1 if you have the `strerror' function. */
376382
#undef HAVE_STRERROR
377383

384+
/* Define to 1 if you have the `strerror_r' function. */
385+
#undef HAVE_STRERROR_R
386+
378387
/* Define to 1 if cpp supports the ANSI # stringizing operator. */
379388
#undef HAVE_STRINGIZE
380389

@@ -579,6 +588,9 @@
579588
/* Define to select SysV-style shared memory. */
580589
#undef USE_SYSV_SHARED_MEMORY
581590

591+
/* Define to 1 to build libpq with threads. (--with-threads) */
592+
#undef USE_THREADS
593+
582594
/* Define to select unnamed POSIX semaphores. */
583595
#undef USE_UNNAMED_POSIX_SEMAPHORES
584596

src/include/port.h

+17-1
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,15 @@
66
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
77
* Portions Copyright (c) 1994, Regents of the University of California
88
*
9-
* $Id: port.h,v 1.6 2003/06/12 08:15:29 momjian Exp $
9+
* $Id: port.h,v 1.7 2003/06/14 14:35:42 momjian Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
1313

14+
/* for thread.c */
15+
#include <pwd.h>
16+
#include <netdb.h>
17+
1418
/* Portable path handling for Unix/Win32 */
1519
bool is_absolute_path(const char *filename);
1620
char *first_path_separator(const char *filename);
@@ -98,3 +102,15 @@ extern long random(void);
98102
#ifndef HAVE_SRANDOM
99103
extern void srandom(unsigned int seed);
100104
#endif
105+
106+
/* thread.h */
107+
extern char *pqStrerror(int errnum, char *strerrbuf, size_t buflen);
108+
109+
extern int pqGetpwuid(uid_t uid, struct passwd *resultbuf, char *buffer,
110+
size_t buflen, struct passwd **result);
111+
112+
extern int pqGethostbyname(const char *name,
113+
struct hostent *resbuf,
114+
char *buf, size_t buflen,
115+
struct hostent **result,
116+
int *herrno);

src/interfaces/libpq/Makefile

+7-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#
55
# Copyright (c) 1994, Regents of the University of California
66
#
7-
# $Header: /cvsroot/pgsql/src/interfaces/libpq/Makefile,v 1.81 2003/06/12 17:31:50 momjian Exp $
7+
# $Header: /cvsroot/pgsql/src/interfaces/libpq/Makefile,v 1.82 2003/06/14 14:35:42 momjian Exp $
88
#
99
#-------------------------------------------------------------------------
1010

@@ -23,7 +23,7 @@ override CPPFLAGS := -I$(srcdir) $(CPPFLAGS) $(THREAD_CFLAGS) -DFRONTEND -DSYSCO
2323
OBJS= fe-auth.o fe-connect.o fe-exec.o fe-misc.o fe-print.o fe-lobj.o \
2424
fe-protocol2.o fe-protocol3.o pqexpbuffer.o pqsignal.o fe-secure.o \
2525
dllist.o md5.o ip.o wchar.o encnames.o \
26-
$(filter crypt.o getaddrinfo.o inet_aton.o snprintf.o strerror.o path.o, $(LIBOBJS))
26+
$(filter crypt.o getaddrinfo.o inet_aton.o snprintf.o strerror.o path.o threads.o, $(LIBOBJS))
2727

2828

2929
# Add libraries that libpq depends (or might depend) on into the
@@ -46,9 +46,13 @@ backend_src = $(top_srcdir)/src/backend
4646
# For port modules, this only happens if configure decides the module
4747
# is needed (see filter hack in OBJS, above).
4848

49-
crypt.c getaddrinfo.c inet_aton.c snprintf.c strerror.c path.c: %.c : $(top_srcdir)/src/port/%.c
49+
crypt.c getaddrinfo.c inet_aton.c snprintf.c strerror.c path.c threads.c: %.c : $(top_srcdir)/src/port/%.c
5050
rm -f $@ && $(LN_S) $< .
5151

52+
# compile this with thread flags
53+
thread.o: thread.c
54+
$(CC) $(CFLAGS) $(THREAD_CFLAGS) -c thread.c
55+
5256
dllist.c: $(backend_src)/lib/dllist.c
5357
rm -f $@ && $(LN_S) $< .
5458

src/port/Makefile

+4-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
# with broken/missing library files.
88

99
# IDENTIFICATION
10-
# $Header: /cvsroot/pgsql/src/port/Makefile,v 1.3 2002/07/27 20:10:05 petere Exp $
10+
# $Header: /cvsroot/pgsql/src/port/Makefile,v 1.4 2003/06/14 14:35:42 momjian Exp $
1111
#
1212
#-------------------------------------------------------------------------
1313

@@ -22,5 +22,8 @@ endif
2222
libpgport.a: $(LIBOBJS)
2323
$(AR) crs $@ $^
2424

25+
thread.o: thread.c
26+
$(CC) $(CFLAGS) $(THREAD_CFLAGS) -c thread.c
27+
2528
clean distclean maintainer-clean:
2629
rm -f libpgport.a $(LIBOBJS)

0 commit comments

Comments
 (0)