Skip to content

Commit ddcb5bb

Browse files
author
Michael Meskes
committed
- Added patch by Magnus Hagander <magnus@hagander.net> to use native
win32 threads. - Fixed regression tests to run threading tests.
1 parent fba8113 commit ddcb5bb

17 files changed

+170
-152
lines changed

src/interfaces/ecpg/ChangeLog

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2177,4 +2177,10 @@ Th Mar 15 08:27:53 CET 2007
21772177
- Synced parser and keyword lists.
21782178
- Copied two token parsing from backend parser to ecpg parser.
21792179
- Also added a test case for this.
2180+
2181+
Thu, 29 Mar 2007 11:18:39 +0200
2182+
2183+
- Added patch by Magnus Hagander <magnus@hagander.net> to use native
2184+
win32 threads.
2185+
- Fixed regression tests to run threading tests.
21802186
- Set ecpg version to 4.3.1.

src/interfaces/ecpg/ecpglib/connect.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1-
/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/connect.c,v 1.40 2007/03/17 19:25:22 meskes Exp $ */
1+
/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/connect.c,v 1.41 2007/03/29 12:02:24 meskes Exp $ */
22

33
#define POSTGRES_ECPG_INTERNAL
44
#include "postgres_fe.h"
55

66
#ifdef ENABLE_THREAD_SAFETY
7+
#ifndef WIN32
78
#include <pthread.h>
9+
#else
10+
#include "ecpg-pthread-win32.h"
11+
#endif
812
#endif
913
#include "ecpgtype.h"
1014
#include "ecpglib.h"
@@ -13,9 +17,14 @@
1317
#include "sqlca.h"
1418

1519
#ifdef ENABLE_THREAD_SAFETY
20+
#ifndef WIN32
1621
static pthread_mutex_t connections_mutex = PTHREAD_MUTEX_INITIALIZER;
1722
static pthread_key_t actual_connection_key;
1823
static pthread_once_t actual_connection_key_once = PTHREAD_ONCE_INIT;
24+
#else
25+
static HANDLE connections_mutex = INVALID_HANDLE_VALUE;
26+
static DWORD actual_connection_key;
27+
#endif /* WIN32 */
1928
#endif
2029
static struct connection *actual_connection = NULL;
2130
static struct connection *all_connections = NULL;
@@ -30,7 +39,13 @@ ecpg_actual_connection_init(void)
3039
void
3140
ecpg_pthreads_init(void)
3241
{
42+
#ifndef WIN32
3343
pthread_once(&actual_connection_key_once, ecpg_actual_connection_init);
44+
#else
45+
static long has_run = 0;
46+
if (InterlockedCompareExchange(&has_run, 1, 0) == 0)
47+
ecpg_actual_connection_init();
48+
#endif
3449
}
3550
#endif
3651

src/interfaces/ecpg/ecpglib/execute.c

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/execute.c,v 1.64 2007/02/11 15:18:17 meskes Exp $ */
1+
/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/execute.c,v 1.65 2007/03/29 12:02:24 meskes Exp $ */
22

33
/*
44
* The aim is to get a simpler inteface to the database routines.
@@ -39,7 +39,6 @@ static char *
3939
quote_postgres(char *arg, bool quote, int lineno)
4040
{
4141
char *res;
42-
int error;
4342
size_t length;
4443
size_t escaped_len;
4544
size_t buffer_len;
@@ -58,13 +57,7 @@ quote_postgres(char *arg, bool quote, int lineno)
5857
if (!res)
5958
return (res);
6059

61-
error = 0;
6260
escaped_len = PQescapeString(res+1, arg, buffer_len);
63-
if (error)
64-
{
65-
ECPGfree(res);
66-
return NULL;
67-
}
6861
if (length == escaped_len)
6962
{
7063
res[0] = res[escaped_len+1] = '\'';

src/interfaces/ecpg/ecpglib/extern.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/extern.h,v 1.22 2007/01/25 16:45:25 meskes Exp $ */
1+
/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/extern.h,v 1.23 2007/03/29 12:02:24 meskes Exp $ */
22

33
#ifndef _ECPG_LIB_EXTERN_H
44
#define _ECPG_LIB_EXTERN_H
55

66
#include "postgres_fe.h"
77
#include "libpq-fe.h"
88
#include "sqlca.h"
9+
#include "ecpg_config.h"
910

1011
enum COMPAT_MODE
1112
{

src/interfaces/ecpg/ecpglib/misc.c

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
1-
/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/misc.c,v 1.34 2007/01/12 10:00:13 meskes Exp $ */
1+
/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/misc.c,v 1.35 2007/03/29 12:02:24 meskes Exp $ */
22

33
#define POSTGRES_ECPG_INTERNAL
44
#include "postgres_fe.h"
55

66
#include <limits.h>
77
#include <unistd.h>
88
#ifdef ENABLE_THREAD_SAFETY
9+
#ifndef WIN32
910
#include <pthread.h>
11+
#else
12+
#include "ecpg-pthread-win32.h"
13+
#endif
1014
#endif
1115
#include "ecpgtype.h"
1216
#include "ecpglib.h"
@@ -58,9 +62,13 @@ static struct sqlca_t sqlca_init =
5862
};
5963

6064
#ifdef ENABLE_THREAD_SAFETY
65+
#ifndef WIN32
6166
static pthread_key_t sqlca_key;
6267
static pthread_once_t sqlca_key_once = PTHREAD_ONCE_INIT;
6368
#else
69+
static DWORD sqlca_key;
70+
#endif
71+
#else
6472
static struct sqlca_t sqlca =
6573
{
6674
{
@@ -90,8 +98,13 @@ static struct sqlca_t sqlca =
9098
#endif
9199

92100
#ifdef ENABLE_THREAD_SAFETY
101+
#ifndef WIN32
93102
static pthread_mutex_t debug_mutex = PTHREAD_MUTEX_INITIALIZER;
94103
static pthread_mutex_t debug_init_mutex = PTHREAD_MUTEX_INITIALIZER;
104+
#else
105+
static HANDLE debug_mutex = INVALID_HANDLE_VALUE;
106+
static HANDLE debug_init_mutex = INVALID_HANDLE_VALUE;
107+
#endif /* WIN32 */
95108
#endif
96109
static int simple_debug = 0;
97110
static FILE *debugstream = NULL;
@@ -138,8 +151,13 @@ ECPGget_sqlca(void)
138151
{
139152
#ifdef ENABLE_THREAD_SAFETY
140153
struct sqlca_t *sqlca;
141-
154+
#ifdef WIN32
155+
static long has_run = 0;
156+
if (InterlockedCompareExchange(&has_run, 1, 0) == 0)
157+
ecpg_sqlca_key_init();
158+
#else
142159
pthread_once(&sqlca_key_once, ecpg_sqlca_key_init);
160+
#endif
143161

144162
sqlca = pthread_getspecific(sqlca_key);
145163
if (sqlca == NULL)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/* $PostgreSQL: pgsql/src/interfaces/ecpg/include/ecpg-pthread-win32.h,v 1.1 2007/03/29 12:02:24 meskes Exp $ */
2+
/*
3+
* pthread mapping macros for win32 native thread implementation
4+
*/
5+
#ifndef _ECPG_PTHREAD_WIN32_H
6+
#define _ECPG_PTHREAD_WIN32_H
7+
#define pthread_mutex_lock(x) do { \
8+
if (*x == INVALID_HANDLE_VALUE) \
9+
*x = CreateMutex(NULL, FALSE, NULL); \
10+
WaitForSingleObject(*x, INFINITE); \
11+
} while (0);
12+
#define pthread_mutex_unlock(x) ReleaseMutex(*x)
13+
#define pthread_getspecific(x) TlsGetValue(x)
14+
#define pthread_setspecific(x,y) TlsSetValue(x,y)
15+
#define pthread_key_create(x,y) *x = TlsAlloc();
16+
#endif

src/interfaces/ecpg/include/ecpg_config.h.in

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,7 @@
1111
(--enable-integer-datetimes) */
1212
#undef USE_INTEGER_DATETIMES
1313

14+
/* Define to 1 to build client libraries as thread-safe code.
15+
* (--enable-thread-safety) */
16+
#undef ENABLE_THREAD_SAFETY
17+

src/interfaces/ecpg/test/Makefile

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# $PostgreSQL: pgsql/src/interfaces/ecpg/test/Makefile,v 1.66 2007/02/09 15:55:59 petere Exp $
1+
# $PostgreSQL: pgsql/src/interfaces/ecpg/test/Makefile,v 1.67 2007/03/29 12:02:24 meskes Exp $
22

33
subdir = src/interfaces/ecpg/test
44
top_builddir = ../../../..
@@ -11,6 +11,9 @@ TEMP_PORT = 5$(DEF_PGPORT)
1111
# default encoding
1212
MULTIBYTE = SQL_ASCII
1313

14+
# threading
15+
THREAD := $(shell grep -q "define ENABLE_THREAD_SAFETY" ../include/ecpg_config.h && echo "--enable-threading")
16+
1417
# locale
1518
NOLOCALE =
1619
ifdef NO_LOCALE
@@ -75,11 +78,11 @@ endif
7578

7679

7780
check: all
78-
sh ./pg_regress --dbname=regress1 --temp-install --top-builddir=$(top_builddir) --temp-port=$(TEMP_PORT) --multibyte=$(MULTIBYTE) --load-language=plpgsql $(NOLOCALE)
81+
sh ./pg_regress --dbname=regress1 --temp-install --top-builddir=$(top_builddir) --temp-port=$(TEMP_PORT) --multibyte=$(MULTIBYTE) --load-language=plpgsql $(NOLOCALE) $(THREAD)
7982

8083
# the same options, but with --listen-on-tcp
8184
checktcp: all
82-
sh ./pg_regress --dbname=regress1 --temp-install --top-builddir=$(top_builddir) --temp-port=$(TEMP_PORT) --multibyte=$(MULTIBYTE) --load-language=plpgsql $(NOLOCALE) --listen-on-tcp
85+
sh ./pg_regress --dbname=regress1 --temp-install --top-builddir=$(top_builddir) --temp-port=$(TEMP_PORT) --multibyte=$(MULTIBYTE) --load-language=plpgsql $(NOLOCALE) --listen-on-tcp $(THREAD)
8386

8487
installcheck: all
8588
sh ./pg_regress --dbname=regress1 --top-builddir=$(top_builddir) --load-language=plpgsql $(NOLOCALE)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Success.

0 commit comments

Comments
 (0)