mirror of
https://github.com/postgres/postgres.git
synced 2025-07-30 11:03:19 +03:00
The attached patch updates the thread test program to run stand-alone on
Windows. The test itself is bypassed in configure as discussed, and libpq has been updated appropriately to allow it to build in thread-safe mode. Dave Page
This commit is contained in:
@ -5,7 +5,7 @@
|
||||
# Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
|
||||
# Portions Copyright (c) 1994, Regents of the University of California
|
||||
#
|
||||
# $PostgreSQL: pgsql/src/interfaces/libpq/Makefile,v 1.136 2005/08/23 20:48:46 momjian Exp $
|
||||
# $PostgreSQL: pgsql/src/interfaces/libpq/Makefile,v 1.137 2005/08/23 21:02:03 momjian Exp $
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
|
||||
@ -43,9 +43,7 @@ libpqrc.o: libpq.rc
|
||||
windres -i libpq.rc -o libpqrc.o
|
||||
|
||||
ifeq ($(enable_thread_safety), yes)
|
||||
# This doesn't work yet because configure test fails. 2004-06-19
|
||||
OBJS += pthread-win32.o
|
||||
PTHREAD_H_WIN32 = pthread.h
|
||||
endif
|
||||
endif
|
||||
|
||||
@ -59,7 +57,7 @@ SHLIB_LINK += -lshfolder -lwsock32 -lws2_32 $(filter -leay32 -lssleay32 -lcomerr
|
||||
endif
|
||||
|
||||
|
||||
all: $(PTHREAD_H_WIN32) def-files $(srcdir)/libpq.rc all-lib
|
||||
all: def-files $(srcdir)/libpq.rc all-lib
|
||||
|
||||
# Shared library stuff
|
||||
include $(top_srcdir)/src/Makefile.shlib
|
||||
@ -122,11 +120,6 @@ $(srcdir)/blibpqdll.def: exports.txt
|
||||
$(srcdir)/libpq.rc: libpq.rc.in $(top_builddir)/src/Makefile.global
|
||||
sed -e 's/\(VERSION.*\),0 *$$/\1,'`date '+%y%j' | sed 's/^0*//'`'/' < $< > $@
|
||||
|
||||
ifneq ($(PTHREAD_H_WIN32), "")
|
||||
pthread.h: $(top_srcdir)/src/interfaces/libpq/pthread.h.win
|
||||
rm -f $@ && $(LN_S) $< .
|
||||
endif
|
||||
|
||||
fe-connect.o: fe-connect.c $(top_builddir)/src/port/pg_config_paths.h
|
||||
|
||||
$(top_builddir)/src/port/pg_config_paths.h:
|
||||
|
@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-connect.c,v 1.319 2005/08/23 20:48:46 momjian Exp $
|
||||
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-connect.c,v 1.320 2005/08/23 21:02:03 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -55,8 +55,12 @@
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_THREAD_SAFETY
|
||||
#ifdef WIN32
|
||||
#include "pthread-win32.h"
|
||||
#else
|
||||
#include <pthread.h>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include "libpq/ip.h"
|
||||
#include "mb/pg_wchar.h"
|
||||
|
@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-exec.c,v 1.173 2005/08/23 20:48:47 momjian Exp $
|
||||
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-exec.c,v 1.174 2005/08/23 21:02:03 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -2156,25 +2156,16 @@ PQoidValue(const PGresult *res)
|
||||
char *endptr = NULL;
|
||||
unsigned long result;
|
||||
|
||||
if (!res || !res->cmdStatus || strncmp(res->cmdStatus, "INSERT ", 7) != 0)
|
||||
if (!res ||
|
||||
!res->cmdStatus ||
|
||||
strncmp(res->cmdStatus, "INSERT ", 7) != 0 ||
|
||||
res->cmdStatus[7] < '0' ||
|
||||
res->cmdStatus[7] > '9')
|
||||
return InvalidOid;
|
||||
|
||||
#ifdef WIN32
|
||||
SetLastError(0);
|
||||
#else
|
||||
errno = 0;
|
||||
#endif
|
||||
result = strtoul(res->cmdStatus + 7, &endptr, 10);
|
||||
|
||||
if (!endptr || (*endptr != ' ' && *endptr != '\0')
|
||||
#ifndef WIN32
|
||||
/*
|
||||
* On WIN32, errno is not thread-safe and GetLastError() isn't set by
|
||||
* strtoul(), so we can't check on this platform.
|
||||
*/
|
||||
|| errno == ERANGE
|
||||
#endif
|
||||
)
|
||||
if (!endptr || (*endptr != ' ' && *endptr != '\0'))
|
||||
return InvalidOid;
|
||||
else
|
||||
return (Oid) result;
|
||||
|
@ -23,7 +23,7 @@
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-misc.c,v 1.118 2005/08/23 20:48:47 momjian Exp $
|
||||
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-misc.c,v 1.119 2005/08/23 21:02:03 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -1133,7 +1133,11 @@ libpq_gettext(const char *msgid)
|
||||
if (!already_bound)
|
||||
{
|
||||
/* dgettext() preserves errno, but bindtextdomain() doesn't */
|
||||
int save_errno = errno;
|
||||
#ifdef WIN32
|
||||
int save_errno = GetLastError();
|
||||
#else
|
||||
int save_errno = errno;
|
||||
#endif
|
||||
const char *ldir;
|
||||
|
||||
already_bound = true;
|
||||
|
@ -10,7 +10,7 @@
|
||||
* didn't really belong there.
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-print.c,v 1.62 2005/08/23 20:48:47 momjian Exp $
|
||||
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-print.c,v 1.63 2005/08/23 21:02:03 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -88,7 +88,7 @@ PQprint(FILE *fout, const PGresult *res, const PQprintOpt *po)
|
||||
int total_line_length = 0;
|
||||
int usePipe = 0;
|
||||
char *pagerenv;
|
||||
#ifdef ENABLE_THREAD_SAFETY
|
||||
#if defined(ENABLE_THREAD_SAFETY) && !defined(WIN32)
|
||||
sigset_t osigset;
|
||||
bool sigpipe_masked = false;
|
||||
bool sigpipe_pending;
|
||||
@ -189,14 +189,14 @@ PQprint(FILE *fout, const PGresult *res, const PQprintOpt *po)
|
||||
if (fout)
|
||||
{
|
||||
usePipe = 1;
|
||||
#ifndef WIN32
|
||||
#ifdef ENABLE_THREAD_SAFETY
|
||||
if (pq_block_sigpipe(&osigset, &sigpipe_pending) == 0)
|
||||
sigpipe_masked = true;
|
||||
#else
|
||||
#ifndef WIN32
|
||||
oldsigpipehandler = pqsignal(SIGPIPE, SIG_IGN);
|
||||
#endif
|
||||
#endif
|
||||
#endif /* ENABLE_THREAD_SAFETY */
|
||||
#endif /* WIN32 */
|
||||
}
|
||||
else
|
||||
fout = stdout;
|
||||
@ -311,16 +311,15 @@ PQprint(FILE *fout, const PGresult *res, const PQprintOpt *po)
|
||||
_pclose(fout);
|
||||
#else
|
||||
pclose(fout);
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_THREAD_SAFETY
|
||||
/* we can't easily verify if EPIPE occurred, so say it did */
|
||||
if (sigpipe_masked)
|
||||
pq_reset_sigpipe(&osigset, sigpipe_pending, true);
|
||||
#else
|
||||
#ifndef WIN32
|
||||
pqsignal(SIGPIPE, oldsigpipehandler);
|
||||
#endif
|
||||
#endif
|
||||
#endif /* ENABLE_THREAD_SAFETY */
|
||||
#endif /* WIN32 */
|
||||
}
|
||||
if (po->html3 && !po->expanded)
|
||||
fputs("</table>\n", fout);
|
||||
|
@ -11,7 +11,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-secure.c,v 1.69 2005/08/23 20:48:47 momjian Exp $
|
||||
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-secure.c,v 1.70 2005/08/23 21:02:03 momjian Exp $
|
||||
*
|
||||
* NOTES
|
||||
* [ Most of these notes are wrong/obsolete, but perhaps not all ]
|
||||
@ -103,8 +103,12 @@
|
||||
#include <sys/stat.h>
|
||||
|
||||
#ifdef ENABLE_THREAD_SAFETY
|
||||
#ifdef WIN32
|
||||
#include "pthread-win32.h"
|
||||
#else
|
||||
#include <pthread.h>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_STRDUP
|
||||
#include "strdup.h"
|
||||
@ -388,20 +392,21 @@ ssize_t
|
||||
pqsecure_write(PGconn *conn, const void *ptr, size_t len)
|
||||
{
|
||||
ssize_t n;
|
||||
|
||||
|
||||
#ifndef WIN32
|
||||
#ifdef ENABLE_THREAD_SAFETY
|
||||
sigset_t osigmask;
|
||||
bool sigpipe_pending;
|
||||
bool got_epipe = false;
|
||||
|
||||
|
||||
if (pq_block_sigpipe(&osigmask, &sigpipe_pending) < 0)
|
||||
return -1;
|
||||
#else
|
||||
#ifndef WIN32
|
||||
pqsigfunc oldsighandler = pqsignal(SIGPIPE, SIG_IGN);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif /* ENABLE_THREAD_SAFETY */
|
||||
#endif /* WIN32 */
|
||||
|
||||
#ifdef USE_SSL
|
||||
if (conn->ssl)
|
||||
{
|
||||
@ -431,7 +436,7 @@ pqsecure_write(PGconn *conn, const void *ptr, size_t len)
|
||||
|
||||
if (n == -1)
|
||||
{
|
||||
#ifdef ENABLE_THREAD_SAFETY
|
||||
#if defined(ENABLE_THREAD_SAFETY) && !defined(WIN32)
|
||||
if (SOCK_ERRNO == EPIPE)
|
||||
got_epipe = true;
|
||||
#endif
|
||||
@ -473,19 +478,19 @@ pqsecure_write(PGconn *conn, const void *ptr, size_t len)
|
||||
#endif
|
||||
{
|
||||
n = send(conn->sock, ptr, len, 0);
|
||||
#ifdef ENABLE_THREAD_SAFETY
|
||||
#if defined(ENABLE_THREAD_SAFETY) && !defined(WIN32)
|
||||
if (n < 0 && SOCK_ERRNO == EPIPE)
|
||||
got_epipe = true;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
#ifndef WIN32
|
||||
#ifdef ENABLE_THREAD_SAFETY
|
||||
pq_reset_sigpipe(&osigmask, sigpipe_pending, got_epipe);
|
||||
#else
|
||||
#ifndef WIN32
|
||||
pqsignal(SIGPIPE, oldsighandler);
|
||||
#endif
|
||||
#endif
|
||||
#endif /* ENABLE_THREAD_SAFETY */
|
||||
#endif /* WIN32 */
|
||||
|
||||
return n;
|
||||
}
|
||||
@ -1232,7 +1237,7 @@ PQgetssl(PGconn *conn)
|
||||
|
||||
#endif /* USE_SSL */
|
||||
|
||||
#ifdef ENABLE_THREAD_SAFETY
|
||||
#if defined(ENABLE_THREAD_SAFETY) && !defined(WIN32)
|
||||
|
||||
/*
|
||||
* Block SIGPIPE for this thread. This prevents send()/write() from exiting
|
||||
|
@ -12,7 +12,7 @@
|
||||
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* $PostgreSQL: pgsql/src/interfaces/libpq/libpq-int.h,v 1.106 2005/08/23 20:48:47 momjian Exp $
|
||||
* $PostgreSQL: pgsql/src/interfaces/libpq/libpq-int.h,v 1.107 2005/08/23 21:02:03 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -30,7 +30,11 @@
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_THREAD_SAFETY
|
||||
#ifdef WIN32
|
||||
#include "pthread-win32.h"
|
||||
#else
|
||||
#include <pthread.h>
|
||||
#endif
|
||||
#include <signal.h>
|
||||
#endif
|
||||
|
||||
@ -481,7 +485,7 @@ extern void pqsecure_close(PGconn *);
|
||||
extern ssize_t pqsecure_read(PGconn *, void *ptr, size_t len);
|
||||
extern ssize_t pqsecure_write(PGconn *, const void *ptr, size_t len);
|
||||
|
||||
#ifdef ENABLE_THREAD_SAFETY
|
||||
#if defined(ENABLE_THREAD_SAFETY) && !defined(WIN32)
|
||||
extern int pq_block_sigpipe(sigset_t *osigset, bool *sigpipe_pending);
|
||||
extern void pq_reset_sigpipe(sigset_t *osigset, bool sigpipe_pending,
|
||||
bool got_epipe);
|
||||
|
@ -5,14 +5,14 @@
|
||||
*
|
||||
* Copyright (c) 2004-2005, PostgreSQL Global Development Group
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/interfaces/libpq/pthread-win32.c,v 1.7 2005/08/23 20:48:47 momjian Exp $
|
||||
* $PostgreSQL: pgsql/src/interfaces/libpq/pthread-win32.c,v 1.8 2005/08/23 21:02:03 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
|
||||
#include <windows.h>
|
||||
#include "pthread.h"
|
||||
#include "pthread-win32.h"
|
||||
|
||||
HANDLE
|
||||
pthread_self()
|
||||
|
Reference in New Issue
Block a user