Rename thread compile flag. Move thread test program to tools/thread,

and improve tests.
This commit is contained in:
Bruce Momjian 2003-09-27 15:32:48 +00:00
parent fae2adecf5
commit 227dd9b427
21 changed files with 112 additions and 42 deletions

6
configure vendored
View File

@ -13292,7 +13292,7 @@ See the comment at the top of src/port/thread.c for more information.
fi
else
# do not use values from template file
THREAD_CFLAGS=
THREAD_CPPFLAGS=
THREAD_LIBS=
fi
@ -13312,7 +13312,7 @@ fi
if test "$enable_thread_safety" = yes -a "$NEED_REENTRANT_FUNCS" = yes ; then
_CFLAGS="$CFLAGS"
_LIBS="$LIBS"
CFLAGS="$CFLAGS $THREAD_CFLAGS"
CFLAGS="$CFLAGS $THREAD_CPPFLAGS"
LIBS="$LIBS $THREAD_LIBS"
@ -18211,7 +18211,7 @@ s,@python_includespec@,$python_includespec,;t t
s,@python_libspec@,$python_libspec,;t t
s,@LIBOBJS@,$LIBOBJS,;t t
s,@HAVE_IPV6@,$HAVE_IPV6,;t t
s,@THREAD_CFLAGS@,$THREAD_CFLAGS,;t t
s,@THREAD_CPPFLAGS@,$THREAD_CPPFLAGS,;t t
s,@THREAD_LIBS@,$THREAD_LIBS,;t t
s,@HAVE_POSIX_SIGNALS@,$HAVE_POSIX_SIGNALS,;t t
s,@MSGFMT@,$MSGFMT,;t t

View File

@ -1,5 +1,5 @@
\dnl Process this file with autoconf to produce a configure script.
dnl $Header: /cvsroot/pgsql/configure.in,v 1.290 2003/09/15 14:32:35 pgsql Exp $
dnl $Header: /cvsroot/pgsql/configure.in,v 1.291 2003/09/27 15:32:47 momjian Exp $
dnl
dnl Developers, please strive to achieve this order:
dnl
@ -1013,10 +1013,10 @@ See the comment at the top of src/port/thread.c for more information.
fi
else
# do not use values from template file
THREAD_CFLAGS=
THREAD_CPPFLAGS=
THREAD_LIBS=
fi
AC_SUBST(THREAD_CFLAGS)
AC_SUBST(THREAD_CPPFLAGS)
AC_SUBST(THREAD_LIBS)
@ -1033,7 +1033,7 @@ AC_SUBST(THREAD_LIBS)
if test "$enable_thread_safety" = yes -a "$NEED_REENTRANT_FUNCS" = yes ; then
_CFLAGS="$CFLAGS"
_LIBS="$LIBS"
CFLAGS="$CFLAGS $THREAD_CFLAGS"
CFLAGS="$CFLAGS $THREAD_CPPFLAGS"
LIBS="$LIBS $THREAD_LIBS"
AC_CHECK_FUNCS([strerror_r getpwuid_r gethostbyname_r])
CFLAGS="$_CFLAGS"

View File

@ -1,5 +1,5 @@
# -*-makefile-*-
# $Header: /cvsroot/pgsql/src/Makefile.global.in,v 1.168 2003/09/07 03:36:02 tgl Exp $
# $Header: /cvsroot/pgsql/src/Makefile.global.in,v 1.169 2003/09/27 15:32:47 momjian Exp $
#------------------------------------------------------------------------------
# All PostgreSQL makefiles include this file and use the variables it sets,
@ -150,7 +150,7 @@ TK_LIBS = @TK_LIBS@
TK_LIB_SPEC = @TK_LIB_SPEC@
TK_XINCLUDES = @TK_XINCLUDES@
THREAD_CFLAGS = @THREAD_CFLAGS@
THREAD_CPPFLAGS = @THREAD_CPPFLAGS@
THREAD_LIBS = @THREAD_LIBS@
have_docbook = @have_docbook@

View File

@ -4,7 +4,7 @@
#
# Copyright (c) 1994, Regents of the University of California
#
# $Header: /cvsroot/pgsql/src/interfaces/ecpg/compatlib/Makefile,v 1.8 2003/08/06 02:19:48 momjian Exp $
# $Header: /cvsroot/pgsql/src/interfaces/ecpg/compatlib/Makefile,v 1.9 2003/09/27 15:32:47 momjian Exp $
#
#-------------------------------------------------------------------------
@ -16,7 +16,7 @@ NAME= ecpg_compat
SO_MAJOR_VERSION= 1
SO_MINOR_VERSION= 0
override CPPFLAGS := -I$(top_srcdir)/src/interfaces/ecpg/include -I$(libpq_srcdir) -I$(top_srcdir)/src/include/utils $(CPPFLAGS) $(THREAD_CFLAGS)
override CPPFLAGS := -I$(top_srcdir)/src/interfaces/ecpg/include -I$(libpq_srcdir) -I$(top_srcdir)/src/include/utils $(CPPFLAGS) $(THREAD_CPPFLAGS)
SHLIB_LINK = -L../pgtypeslib -lpgtypes -L../ecpglib -lecpg $(THREAD_LIBS)
OBJS= informix.o

View File

@ -4,7 +4,7 @@
#
# Copyright (c) 1994, Regents of the University of California
#
# $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/Makefile,v 1.7 2003/08/01 16:18:04 petere Exp $
# $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/Makefile,v 1.8 2003/09/27 15:32:47 momjian Exp $
#
#-------------------------------------------------------------------------
@ -16,7 +16,7 @@ NAME= ecpg
SO_MAJOR_VERSION= 4
SO_MINOR_VERSION= 0
override CPPFLAGS := -I$(top_srcdir)/src/interfaces/ecpg/include -I$(libpq_srcdir) $(CPPFLAGS) $(THREAD_CFLAGS)
override CPPFLAGS := -I$(top_srcdir)/src/interfaces/ecpg/include -I$(libpq_srcdir) $(CPPFLAGS) $(THREAD_CPPFLAGS)
OBJS= execute.o typename.o descriptor.o data.o error.o prepare.o memory.o \
connect.o misc.o

View File

@ -4,7 +4,7 @@
#
# Copyright (c) 1994, Regents of the University of California
#
# $Header: /cvsroot/pgsql/src/interfaces/ecpg/pgtypeslib/Makefile,v 1.11 2003/08/07 04:03:18 momjian Exp $
# $Header: /cvsroot/pgsql/src/interfaces/ecpg/pgtypeslib/Makefile,v 1.12 2003/09/27 15:32:47 momjian Exp $
#
#-------------------------------------------------------------------------
@ -16,7 +16,7 @@ NAME= pgtypes
SO_MAJOR_VERSION= 1
SO_MINOR_VERSION= 0
override CPPFLAGS := -I$(top_srcdir)/src/interfaces/ecpg/include -I$(top_srcdir)/src/include/utils $(CPPFLAGS) $(THREAD_CFLAGS) -g
override CPPFLAGS := -I$(top_srcdir)/src/interfaces/ecpg/include -I$(top_srcdir)/src/include/utils $(CPPFLAGS) $(THREAD_CPPFLAGS) -g
SHLIB_LINK += -lm
OBJS= numeric.o datetime.o common.o dt_common.o timestamp.o interval.o \

View File

@ -1,4 +1,4 @@
# $Header: /cvsroot/pgsql/src/interfaces/ecpg/preproc/Makefile,v 1.93 2003/08/06 02:19:51 momjian Exp $
# $Header: /cvsroot/pgsql/src/interfaces/ecpg/preproc/Makefile,v 1.94 2003/09/27 15:32:48 momjian Exp $
subdir = src/interfaces/ecpg/preproc
top_builddir = ../../../..
@ -8,7 +8,7 @@ MAJOR_VERSION=3
MINOR_VERSION=0
PATCHLEVEL=0
override CPPFLAGS := -I$(srcdir)/../include -I$(srcdir) $(CPPFLAGS) $(THREAD_CFLAGS) \
override CPPFLAGS := -I$(srcdir)/../include -I$(srcdir) $(CPPFLAGS) $(THREAD_CPPFLAGS) \
-DMAJOR_VERSION=$(MAJOR_VERSION) \
-DMINOR_VERSION=$(MINOR_VERSION) -DPATCHLEVEL=$(PATCHLEVEL) \
-DINCLUDE_PATH=\"$(includedir)\"

View File

@ -1,10 +1,10 @@
# $Header: /cvsroot/pgsql/src/interfaces/ecpg/test/Makefile,v 1.40 2003/08/06 02:19:51 momjian Exp $
# $Header: /cvsroot/pgsql/src/interfaces/ecpg/test/Makefile,v 1.41 2003/09/27 15:32:48 momjian Exp $
subdir = src/interfaces/ecpg/test
top_builddir = ../../../..
include $(top_builddir)/src/Makefile.global
override CPPFLAGS := -I$(srcdir)/../include -I$(libpq_srcdir) $(CPPFLAGS) $(THREAD_CFLAGS)
override CPPFLAGS := -I$(srcdir)/../include -I$(libpq_srcdir) $(CPPFLAGS) $(THREAD_CPPFLAGS)
ECPG = ../preproc/ecpg -I$(srcdir)/../include

View File

@ -4,7 +4,7 @@
#
# Copyright (c) 1994, Regents of the University of California
#
# $Header: /cvsroot/pgsql/src/interfaces/libpq/Makefile,v 1.93 2003/09/07 03:43:57 momjian Exp $
# $Header: /cvsroot/pgsql/src/interfaces/libpq/Makefile,v 1.94 2003/09/27 15:32:48 momjian Exp $
#
#-------------------------------------------------------------------------
@ -18,7 +18,7 @@ NAME= pq
SO_MAJOR_VERSION= 3
SO_MINOR_VERSION= 1
override CPPFLAGS := -I$(srcdir) $(CPPFLAGS) $(THREAD_CFLAGS) -DFRONTEND -DSYSCONFDIR='"$(sysconfdir)"'
override CPPFLAGS := -I$(srcdir) $(CPPFLAGS) $(THREAD_CPPFLAGS) -DFRONTEND -DSYSCONFDIR='"$(sysconfdir)"'
OBJS= fe-auth.o fe-connect.o fe-exec.o fe-misc.o fe-print.o fe-lobj.o \
fe-protocol2.o fe-protocol3.o pqexpbuffer.o pqsignal.o fe-secure.o \

View File

@ -11,7 +11,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-secure.c,v 1.30 2003/09/05 02:08:36 momjian Exp $
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-secure.c,v 1.31 2003/09/27 15:32:48 momjian Exp $
*
* NOTES
* The client *requires* a valid server certificate. Since
@ -469,7 +469,13 @@ verify_peer(PGconn *conn)
struct hostent hpstr;
char buf[BUFSIZ];
int herrno = 0;
/*
* Currently, pqGethostbyname() is used only on platforms that
* don't have getaddrinfo(). If you enable this function,
* you should convert the pqGethostbyname() function call to
* use getaddrinfo().
*/
pqGethostbyname(conn->peer_cn, &hpstr, buf, sizeof(buf),
&h, &herrno);
}

View File

@ -7,7 +7,7 @@
# with broken/missing library files.
# IDENTIFICATION
# $Header: /cvsroot/pgsql/src/port/Makefile,v 1.6 2003/08/13 03:12:04 momjian Exp $
# $Header: /cvsroot/pgsql/src/port/Makefile,v 1.7 2003/09/27 15:32:48 momjian Exp $
#
#-------------------------------------------------------------------------
@ -23,7 +23,7 @@ libpgport.a: $(LIBOBJS)
$(AR) crs $@ $^
thread.o: thread.c
$(CC) $(CFLAGS) $(CPPFLAGS) $(THREAD_CFLAGS) -c $<
$(CC) $(CFLAGS) $(CPPFLAGS) $(THREAD_CPPFLAGS) -c $<
clean distclean maintainer-clean:
rm -f libpgport.a $(LIBOBJS)

View File

@ -7,7 +7,7 @@
*
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
*
* $Id: thread.c,v 1.8 2003/09/15 02:30:29 momjian Exp $
* $Id: thread.c,v 1.9 2003/09/27 15:32:48 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@ -165,7 +165,9 @@ pqGetpwuid(uid_t uid, struct passwd *resultbuf, char *buffer,
/*
* Wrapper around gethostbyname() or gethostbyname_r() to mimic
* POSIX gethostbyname_r() behaviour, if it is not available or required.
* This function is called _only_ by our getaddinfo() portability function.
*/
#ifndef HAVE_GETADDRINFO
int
pqGethostbyname(const char *name,
struct hostent *resultbuf,
@ -213,7 +215,7 @@ pqGethostbyname(const char *name,
for (i = 0; (*result)->h_aliases[i]; i++, pointers++)
len += (*result)->h_length;
if (MAXALIGN(len) + pointers * sizeof(char *) + strlen((*result)->h_name) + 1 <= buflen)
if (pointers * sizeof(char *) + MAXALIGN(len) + strlen((*result)->h_name) + 1 <= buflen)
{
memcpy(resultbuf, *result, sizeof(struct hostent));
@ -242,6 +244,7 @@ pqGethostbyname(const char *name,
pbuffer++;
/* Place at end for cleaner alignment */
buffer = MAXALIGN(buffer);
strcpy(buffer, (*result)->h_name);
resultbuf->h_name = buffer;
buffer += strlen(resultbuf->h_name) + 1;
@ -269,3 +272,4 @@ pqGethostbyname(const char *name,
return -1;
#endif
}
#endif

View File

@ -11,4 +11,4 @@ case $host_os in
esac
SUPPORTS_THREADS=yes
NEED_REENTRANT_FUNCS=no # verified 4.3 2003-09-03
NEED_REENTRANT_FUNCS=no # verified 4.3 2003-09-26

View File

@ -7,9 +7,10 @@ esac
SUPPORTS_THREADS=yes
NEED_REENTRANT_FUNCS=yes # 4.8, 5.1 2003-09-12
THREAD_CPPFLAGS="-D_THREAD_SAFE"
case $host_os in
freebsd2*|freebsd3*|freebsd4*)
THREAD_CFLAGS="-pthread"
THREAD_LIBS="-pthread"
;;
*)
THREAD_LIBS="-lc_r"

View File

@ -4,6 +4,6 @@ CPPFLAGS="-D_GNU_SOURCE"
SUPPORTS_THREADS=yes
NEED_REENTRANT_FUNCS=yes # verified glibc 2.1 2003-09-03
THREAD_CFLAGS="-D_REENTRANT -D_THREAD_SAFE -D_POSIX_PTHREAD_SEMANTICS"
THREAD_CPPFLAGS="-D_REENTRANT -D_THREAD_SAFE -D_POSIX_PTHREAD_SEMANTICS"
THREAD_LIBS="-lpthread"

View File

@ -7,4 +7,4 @@ fi
SUPPORTS_THREADS=yes
NEED_REENTRANT_FUNCS=no # 4.0 2003-09-13
THREAD_CFLAGS="-pthread"
THREAD_LIBS="-pthread"

View File

@ -7,5 +7,5 @@ fi
SUPPORTS_THREADS=yes
NEED_REENTRANT_FUNCS=yes # 5.6 2003-09-13
THREAD_CFLAGS="-pthread"
THREAD_LIBS="-pthread"

View File

@ -1,14 +1,14 @@
if test "$GCC" = yes; then
CFLAGS=-O2
THREAD_CFLAGS="-pthread"
THREAD_CPPFLAGS="-pthread"
else
# the -Kno_host is temporary for a bug in the compiler. See -hackers
# discussion on 7-8/Aug/2003.
# when the 7.1.3UP3 or later compiler is out, we can do a version check.
CFLAGS='-O -Kinline,no_host'
THREAD_CFLAGS="-K pthread"
THREAD_CPPFLAGS="-K pthread"
fi
SUPPORTS_THREADS=yes
NEED_REENTRANT_FUNCS=no # verified 7.1.3 2003-09-03
THREAD_CFLAGS="$THREAD_CFLAGS -D_REENTRANT"
THREAD_CPPFLAGS="$THREAD_CPPFLAGS -D_REENTRANT"

25
src/tools/thread/Makefile Normal file
View File

@ -0,0 +1,25 @@
#-------------------------------------------------------------------------
#
# Makefile for tools/thread
#
# Copyright (C) 2003 by PostgreSQL Global Development Team
#
# $Header: /cvsroot/pgsql/src/tools/thread/Attic/Makefile,v 1.1 2003/09/27 15:32:48 momjian Exp $
#
#-------------------------------------------------------------------------
subdir = tools/thread
top_builddir = ../../..
include $(top_builddir)/src/Makefile.global
override CFLAGS += $(THREAD_CPPFLAGS)
LDFLAGS += $(THREAD_LIBS)
all: thread_test
thread_test: thread_test.o
$(CC) $(CFLAGS) $(LDFLAGS) $^ $(LIBS) -o $@
clean distclean maintainer-clean:
rm -f thread_test$(X) thread_test.o

8
src/tools/thread/README Normal file
View File

@ -0,0 +1,8 @@
This program should be run by developers wishing to enable threading on
new platforms.
Run thread_test program to determine if your native libc functions are
thread-safe, or if we should use *_r functions or thread locking.
Make sure you have added any needed 'THREAD_CPPFLAGS' and 'THREAD_LIBS'
defines to your template/${port} file before compiling this program.

View File

@ -6,7 +6,7 @@
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* $Header: /cvsroot/pgsql/src/tools/Attic/test_thread_funcs.c,v 1.3 2003/09/03 22:34:08 momjian Exp $
* $Header: /cvsroot/pgsql/src/tools/thread/Attic/thread_test.c,v 1.1 2003/09/27 15:32:48 momjian Exp $
*
* This program tests to see if your standard libc functions use
* pthread_setspecific()/pthread_getspecific() to be thread-safe.
@ -17,9 +17,6 @@
* to see if the pointers are different for different threads. If they
* are, the function is thread-safe.
*
* This program must be compiled with the thread flags required by your
* operating system. See src/template for the appropriate flags, if any.
*
*-------------------------------------------------------------------------
*/
@ -37,8 +34,10 @@
void func_call_1(void);
void func_call_2(void);
#ifndef HAVE_GETADDRINFO
struct hostent *hostent_p1;
struct hostent *hostent_p2;
#endif
struct passwd *passwd_p1;
struct passwd *passwd_p2;
@ -57,24 +56,47 @@ int main(int argc, char *argv[])
return 1;
}
printf("\
Make sure you have added any needed 'THREAD_CPPFLAGS' and 'THREAD_LIBS'\n\
defines to your template/${port} file before compiling this program.\n\n"
);
pthread_create(&thread1, NULL, (void * (*)(void *)) func_call_1, NULL);
pthread_create(&thread2, NULL, (void * (*)(void *)) func_call_2, NULL);
pthread_join(thread1, NULL);
pthread_join(thread2, NULL);
#ifndef HAVE_GETADDRINFO
if (hostent_p1 == hostent_p2)
printf("Your gethostbyname() is _not_ thread-safe\n");
#endif
if (passwd_p1 == passwd_p2)
printf("Your getpwuid() is _not_ thread-safe\n");
if (strerror_p1 == strerror_p2)
printf("Your strerror() is _not_ thread-safe\n");
if (hostent_p1 != hostent_p2 &&
if (
#ifndef HAVE_GETADDRINFO
hostent_p1 != hostent_p2 &&
#endif
passwd_p1 != passwd_p2 &&
strerror_p1 != strerror_p2)
printf("Your functions are all thread-safe\n");
{
printf("All your non-*_r functions are thread-safe.\n");
printf("Add this to your template/${port} file:\n\n");
printf("\
SUPPORTS_THREADS=yes\n\
NEED_REENTRANT_FUNCS=no\n"
);
}
else
printf("Your functions are _not_ all thread-safe\n");
{
printf("Not all non-*_r functions are thread-safe.\n");
printf("Add this to your template/${port} file:\n\n");
printf("\
SUPPORTS_THREADS=yes\n\
NEED_REENTRANT_FUNCS=yes\n"
);
}
return 0;
}
@ -82,6 +104,7 @@ int main(int argc, char *argv[])
void func_call_1(void) {
void *p;
#ifndef HAVE_GETADDRINFO
hostent_p1 = gethostbyname("yahoo.com");
p = gethostbyname("slashdot.org");
if (hostent_p1 != p)
@ -89,6 +112,7 @@ void func_call_1(void) {
printf("Your gethostbyname() changes the static memory area between calls\n");
hostent_p1 = NULL; /* force thread-safe failure report */
}
#endif
passwd_p1 = getpwuid(0);
p = getpwuid(1);
@ -109,6 +133,7 @@ void func_call_1(void) {
void func_call_2(void) {
void *p;
#ifndef HAVE_GETADDRINFO
hostent_p2 = gethostbyname("google.com");
p = gethostbyname("postgresql.org");
if (hostent_p2 != p)
@ -116,6 +141,7 @@ void func_call_2(void) {
printf("Your gethostbyname() changes the static memory area between calls\n");
hostent_p2 = NULL; /* force thread-safe failure report */
}
#endif
passwd_p2 = getpwuid(2);
p = getpwuid(3);