Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitaf70d57

Browse files
committed
Enable thread safety for win32.mak build of PostgreSQL.
Andreas Pflug
1 parent1181ea6 commitaf70d57

File tree

5 files changed

+92
-8
lines changed

5 files changed

+92
-8
lines changed

‎src/interfaces/libpq/fe-connect.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-connect.c,v 1.274 2004/06/1022:26:24 momjian Exp $
11+
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-connect.c,v 1.275 2004/06/19 04:22:17 momjian Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -882,10 +882,12 @@ connectDBStart(PGconn *conn)
882882
constchar*node=NULL;
883883
intret;
884884
#ifdefENABLE_THREAD_SAFETY
885+
#ifndefWIN32
885886
staticpthread_once_tcheck_sigpipe_once=PTHREAD_ONCE_INIT;
886887

887888
/* Check only on first connection request */
888889
pthread_once(&check_sigpipe_once,check_sigpipe_handler);
890+
#endif
889891
#endif
890892

891893
if (!conn)
@@ -3183,11 +3185,19 @@ PQinitSSL(int do_init)
31833185
}
31843186

31853187
staticpgthreadlock_tdefault_threadlock;
3188+
31863189
staticvoid
31873190
default_threadlock(intacquire)
31883191
{
31893192
#ifdefENABLE_THREAD_SAFETY
3193+
#ifndefWIN32
31903194
staticpthread_mutex_tsinglethread_lock=PTHREAD_MUTEX_INITIALIZER;
3195+
#else
3196+
staticpthread_mutex_tsinglethread_lock;
3197+
staticlongmutex_initialized=0;
3198+
if (!InterlockedExchange(&mutex_initialized,1L))
3199+
pthread_mutex_init(&singlethread_lock,NULL);
3200+
#endif
31913201
if (acquire)
31923202
pthread_mutex_lock(&singlethread_lock);
31933203
else

‎src/interfaces/libpq/fe-secure.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*
1212
*
1313
* IDENTIFICATION
14-
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-secure.c,v 1.41 2004/06/03 00:13:19 momjian Exp $
14+
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-secure.c,v 1.42 2004/06/19 04:22:17 momjian Exp $
1515
*
1616
* NOTES
1717
* The client *requires* a valid server certificate. Since
@@ -864,8 +864,14 @@ static int
864864
init_ssl_system(PGconn*conn)
865865
{
866866
#ifdefENABLE_THREAD_SAFETY
867-
staticpthread_mutex_tinit_mutex=PTHREAD_MUTEX_INITIALIZER;
868-
867+
#ifndefWIN32
868+
staticpthread_mutex_tinit_mutex=PTHREAD_MUTEX_INITIALIZER;
869+
#else
870+
staticpthread_mutex_tinit_mutex;
871+
staticlongmutex_initialized=0L;
872+
if (!InterlockedExchange(&mutex_initialized,1L))
873+
pthread_mutex_init(&init_mutex,NULL);
874+
#endif
869875
pthread_mutex_lock(&init_mutex);
870876

871877
if (pq_initssllib&&pq_lockarray==NULL) {
@@ -1171,6 +1177,7 @@ PQgetssl(PGconn *conn)
11711177

11721178

11731179
#ifdefENABLE_THREAD_SAFETY
1180+
#ifndefWIN32
11741181
/*
11751182
*Check SIGPIPE handler and perhaps install our own.
11761183
*/
@@ -1211,6 +1218,7 @@ sigpipe_handler_ignore_send(int signo)
12111218
exit(128+SIGPIPE);/* typical return value for SIG_DFL */
12121219
}
12131220
#endif
1221+
#endif
12141222

12151223
/*
12161224
*Indicates whether the current thread is in send()

‎src/interfaces/libpq/pthread-win32.c

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*-------------------------------------------------------------------------
2+
*
3+
* pthread-win32.c
4+
* partial pthread implementation for win32
5+
*
6+
* Copyright (c) 2004, PostgreSQL Global Development Group
7+
* IDENTIFICATION
8+
* $PostgreSQL: pgsql/src/interfaces/libpq/pthread-win32.c,v 1.1 2004/06/19 04:22:17 momjian Exp $
9+
*
10+
*-------------------------------------------------------------------------
11+
*/
12+
13+
14+
#include"windows.h"
15+
#include"pthread.h"
16+
17+
HANDLEpthread_self()
18+
{
19+
returnGetCurrentThread();
20+
}
21+
22+
voidpthread_setspecific(pthread_key_tkey,void*val)
23+
{
24+
}
25+
26+
void*pthread_getspecific(pthread_key_tkey)
27+
{
28+
returnNULL;
29+
}
30+
31+
voidpthread_mutex_init(pthread_mutex_t*mp,void*attr)
32+
{
33+
*mp=CreateMutex(0,0,0);
34+
}
35+
36+
voidpthread_mutex_lock(pthread_mutex_t*mp)
37+
{
38+
WaitForSingleObject(*mp,INFINITE);
39+
}
40+
41+
voidpthread_mutex_unlock(pthread_mutex_t*mp)
42+
{
43+
ReleaseMutex(*mp);
44+
}

‎src/interfaces/libpq/pthread.h.win32

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#ifndef __PTHREAD_H
2+
#define __PTHREAD_H
3+
4+
typedef ULONG pthread_key_t;
5+
typedef HANDLE pthread_mutex_t;
6+
typedef int pthread_once_t;
7+
8+
HANDLE pthread_self();
9+
10+
void pthread_setspecific(pthread_key_t, void*);
11+
void* pthread_getspecific(pthread_key_t);
12+
13+
void pthread_mutex_init(pthread_mutex_t *, void *attr);
14+
void pthread_mutex_lock(pthread_mutex_t*); // blocking
15+
void pthread_mutex_unlock(pthread_mutex_t*);
16+
17+
#endif

‎src/interfaces/libpq/win32.mak

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# and a Win32 dynamic library libpq(d).dll with import library libpq(d)dll.lib
55
# USE_SSL=1 will compile with OpenSSL
66
# DEBUG=1 compiles with debugging symbols
7-
7+
# ENABLE_THREAD_SAFETY=1 compiles with threading enabled
88

99
!MESSAGE Building the Win32 static library...
1010
!MESSAGE
@@ -74,21 +74,25 @@ CLEAN :
7474
-@erase"$(OUTDIR)\$(OUTFILENAME)dll.lib"
7575
-@erase"$(INTDIR)\wchar.obj"
7676
-@erase"$(INTDIR)\encnames.obj"
77+
-@erase"$(INTDIR)\pthread-win32.obj"
7778

7879

7980

80-
config: ..\..\include\pg_config.h pg_config_paths.h
81+
config: ..\..\include\pg_config.hpthread.hpg_config_paths.h
8182

8283
..\..\include\pg_config.h: ..\..\include\pg_config.h.win32
8384
copy ..\..\include\pg_config.h.win32 ..\..\include\pg_config.h
8485

86+
pthread.h: pthread.h.win32
87+
copy pthread.h.win32 pthread.h
88+
8589
pg_config_paths.h: win32.mak
8690
echo#define SYSCONFDIR "" >pg_config_paths.h
8791

8892
"$(OUTDIR)" :
8993
if not exist "$(OUTDIR)/$(NULL)" mkdir "$(OUTDIR)"
9094

91-
CPP_PROJ=/nologo /W3 /GX$(OPT) /I "..\..\include" /D "FRONTEND"$(DEBUGDEF) /D\
95+
CPP_PROJ=/nologo /W3 /GX$(OPT) /I "..\..\include" /I. /D "FRONTEND"$(DEBUGDEF) /D\
9296
"WIN32" /D "_WINDOWS" /Fp"$(INTDIR)\libpq.pch" /YX\
9397
/Fo"$(INTDIR)\\" /Fd"$(INTDIR)\\" /FD /c /D "HAVE_VSNPRINTF" /D "HAVE_STRDUP"
9498

@@ -127,7 +131,8 @@ LIB32_OBJS= \
127131
"$(INTDIR)\fe-secure.obj"\
128132
"$(INTDIR)\pqexpbuffer.obj"\
129133
"$(INTDIR)\wchar.obj"\
130-
"$(INTDIR)\encnames.obj"
134+
"$(INTDIR)\encnames.obj"\
135+
"$(INTDIR)\pthread-win32.obj"
131136

132137

133138
RSC_PROJ=/l 0x409 /fo"$(INTDIR)\libpq.res"

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp