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

Commitc4a6c2f

Browse files
author
Michael Meskes
committed
Hopefully fixed some stuff that causes Windows builds to fail.
1 parent6d673a6 commitc4a6c2f

File tree

9 files changed

+69
-60
lines changed

9 files changed

+69
-60
lines changed

‎src/interfaces/ecpg/ChangeLog

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2252,5 +2252,9 @@ Tue, 02 Oct 2007 11:32:25 +0200
22522252

22532253
- ITAGAKI Takahiro <itagaki.takahiro@oss.ntt.co.jp> added thread-safe
22542254
descriptor handling
2255+
2256+
Wed, 03 Oct 2007 10:48:39 +0200
2257+
2258+
- Hopefully fixed some stuff that causes Windows builds to fail.
22552259
- Set ecpg library version to 6.0.
22562260
- Set ecpg version to 4.4.

‎src/interfaces/ecpg/ecpglib/connect.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/connect.c,v 1.45 2007/10/02 09:49:59 meskes Exp $ */
1+
/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/connect.c,v 1.46 2007/10/03 08:55:22 meskes Exp $ */
22

33
#definePOSTGRES_ECPG_INTERNAL
44
#include"postgres_fe.h"
@@ -11,17 +11,15 @@
1111
#include"sqlca.h"
1212

1313
#ifdefENABLE_THREAD_SAFETY
14-
NON_EXEC_STATICpthread_mutex_tconnections_mutex=PTHREAD_MUTEX_INITIALIZER;
14+
staticpthread_mutex_tconnections_mutex=PTHREAD_MUTEX_INITIALIZER;
1515
staticpthread_key_tactual_connection_key;
16-
#ifndefWIN32
1716
staticpthread_once_tactual_connection_key_once=PTHREAD_ONCE_INIT;
1817
#endif
19-
#endif
2018
staticstructconnection*actual_connection=NULL;
2119
staticstructconnection*all_connections=NULL;
2220

2321
#ifdefENABLE_THREAD_SAFETY
24-
NON_EXEC_STATICvoid
22+
staticvoid
2523
ecpg_actual_connection_init(void)
2624
{
2725
pthread_key_create(&actual_connection_key,NULL);
@@ -447,7 +445,6 @@ ECPGconnect(int lineno, int c, const char *name, const char *user, const char *p
447445

448446
this->cache_head=NULL;
449447
this->prep_stmts=NULL;
450-
this->descriptors=NULL;
451448

452449
if (all_connections==NULL)
453450
this->next=NULL;

‎src/interfaces/ecpg/ecpglib/descriptor.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* dynamic SQL support routines
22
*
3-
* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/descriptor.c,v 1.24 2007/10/02 09:49:59 meskes Exp $
3+
* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/descriptor.c,v 1.25 2007/10/03 08:55:22 meskes Exp $
44
*/
55

66
#definePOSTGRES_ECPG_INTERNAL
@@ -21,17 +21,15 @@ static void descriptor_deallocate_all(struct descriptor *list);
2121
/* We manage descriptors separately for each thread. */
2222
#ifdefENABLE_THREAD_SAFETY
2323
staticpthread_key_tdescriptor_key;
24-
#ifndefWIN32
2524
staticpthread_once_tdescriptor_once=PTHREAD_ONCE_INIT;
26-
#endif
2725

2826
staticvoid
2927
descriptor_destructor(void*arg)
3028
{
3129
descriptor_deallocate_all(arg);
3230
}
3331

34-
NON_EXEC_STATICvoid
32+
staticvoid
3533
descriptor_key_init(void)
3634
{
3735
pthread_key_create(&descriptor_key,descriptor_destructor);

‎src/interfaces/ecpg/ecpglib/extern.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/extern.h,v 1.29 2007/10/02 09:49:59 meskes Exp $ */
1+
/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/extern.h,v 1.30 2007/10/03 08:55:22 meskes Exp $ */
22

33
#ifndef_ECPG_LIB_EXTERN_H
44
#define_ECPG_LIB_EXTERN_H
@@ -36,8 +36,6 @@ bool ECPGget_data(const PGresult *, int, int, int, enum ECPGttype type,
3636

3737
#ifdefENABLE_THREAD_SAFETY
3838
voidecpg_pthreads_init(void);
39-
#else
40-
#defineecpg_pthreads_init()((void)0)
4139
#endif
4240
structconnection*ECPGget_connection(constchar*);
4341
char*ECPGalloc(long,int);
@@ -94,7 +92,6 @@ struct connection
9492
intautocommit;
9593
structECPGtype_information_cache*cache_head;
9694
structprepared_statement*prep_stmts;
97-
structdescriptor*descriptors;
9895
structconnection*next;
9996
};
10097

‎src/interfaces/ecpg/ecpglib/memory.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/memory.c,v 1.9 2007/09/30 11:38:48 meskes Exp $ */
1+
/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/memory.c,v 1.10 2007/10/03 08:55:22 meskes Exp $ */
22

33
#definePOSTGRES_ECPG_INTERNAL
44
#include"postgres_fe.h"
@@ -70,17 +70,15 @@ struct auto_mem
7070

7171
#ifdefENABLE_THREAD_SAFETY
7272
staticpthread_key_tauto_mem_key;
73-
#ifndefWIN32
7473
staticpthread_once_tauto_mem_once=PTHREAD_ONCE_INIT;
75-
#endif
7674

7775
staticvoid
7876
auto_mem_destructor(void*arg)
7977
{
8078
ECPGfree_auto_mem();
8179
}
8280

83-
NON_EXEC_STATICvoid
81+
staticvoid
8482
auto_mem_key_init(void)
8583
{
8684
pthread_key_create(&auto_mem_key,auto_mem_destructor);

‎src/interfaces/ecpg/ecpglib/misc.c

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/misc.c,v 1.38 2007/10/02 09:49:59 meskes Exp $ */
1+
/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/misc.c,v 1.39 2007/10/03 08:55:22 meskes Exp $ */
22

33
#definePOSTGRES_ECPG_INTERNAL
44
#include"postgres_fe.h"
@@ -57,9 +57,7 @@ static struct sqlca_t sqlca_init =
5757

5858
#ifdefENABLE_THREAD_SAFETY
5959
staticpthread_key_tsqlca_key;
60-
#ifndefWIN32
6160
staticpthread_once_tsqlca_key_once=PTHREAD_ONCE_INIT;
62-
#endif
6361
#else
6462
staticstructsqlca_tsqlca=
6563
{
@@ -90,8 +88,8 @@ static struct sqlca_t sqlca =
9088
#endif
9189

9290
#ifdefENABLE_THREAD_SAFETY
93-
NON_EXEC_STATICpthread_mutex_tdebug_mutex=PTHREAD_MUTEX_INITIALIZER;
94-
NON_EXEC_STATICpthread_mutex_tdebug_init_mutex=PTHREAD_MUTEX_INITIALIZER;
91+
staticpthread_mutex_tdebug_mutex=PTHREAD_MUTEX_INITIALIZER;
92+
staticpthread_mutex_tdebug_init_mutex=PTHREAD_MUTEX_INITIALIZER;
9593
#endif
9694
staticintsimple_debug=0;
9795
staticFILE*debugstream=NULL;
@@ -125,7 +123,7 @@ ecpg_sqlca_key_destructor(void *arg)
125123
free(arg);/* sqlca structure allocated in ECPGget_sqlca */
126124
}
127125

128-
NON_EXEC_STATICvoid
126+
staticvoid
129127
ecpg_sqlca_key_init(void)
130128
{
131129
pthread_key_create(&sqlca_key,ecpg_sqlca_key_destructor);
@@ -415,24 +413,37 @@ ECPGis_noind_null(enum ECPGttype type, void *ptr)
415413
}
416414

417415
#ifdefWIN32
416+
#ifdefENABLE_THREAD_SAFETY
417+
418+
void
419+
win32_pthread_mutex(volatilepthread_mutex_t*mutex)
420+
{
421+
if (mutex->handle==NULL)
422+
{
423+
while (InterlockedExchange((LONG*)&mutex->initlock,1)==1)
424+
Sleep(0);
425+
if (mutex->handle==NULL)
426+
mutex->handle=CreateMutex(NULL, FALSE,NULL);
427+
InterlockedExchange((LONG*)&mutex->initlock,0);
428+
}
429+
}
418430

419-
/*
420-
* Initialize mutexes and call init-once functions on loading.
421-
*/
431+
staticpthread_mutex_twin32_pthread_once_lock=PTHREAD_MUTEX_INITIALIZER;
422432

423-
BOOLWINAPI
424-
DllMain(HANDLEmodule,DWORDreason,LPVOIDreserved)
433+
void
434+
win32_pthread_once(volatilepthread_once_t*once,void (*fn)(void))
425435
{
426-
if (reason==DLL_PROCESS_ATTACH)
436+
if (!*once)
427437
{
428-
connections_mutex=CreateMutex(NULL, FALSE,NULL);
429-
debug_mutex=CreateMutex(NULL, FALSE,NULL);
430-
debug_init_mutex=CreateMutex(NULL, FALSE,NULL);
431-
auto_mem_key_init();
432-
ecpg_actual_connection_init();
433-
ecpg_sqlca_key_init();
434-
descriptor_key_init();
438+
pthread_mutex_lock(&win32_pthread_once_lock);
439+
if (!*once)
440+
{
441+
*once= true;
442+
fn();
443+
}
444+
pthread_mutex_unlock(&win32_pthread_once_lock);
435445
}
436-
return TRUE;
437446
}
438-
#endif
447+
448+
#endif/* ENABLE_THREAD_SAFETY */
449+
#endif/* WIN32 */

‎src/interfaces/ecpg/include/ecpg-pthread-win32.h

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $PostgreSQL: pgsql/src/interfaces/ecpg/include/ecpg-pthread-win32.h,v 1.3 2007/10/02 09:49:59 meskes Exp $ */
1+
/* $PostgreSQL: pgsql/src/interfaces/ecpg/include/ecpg-pthread-win32.h,v 1.4 2007/10/03 08:55:23 meskes Exp $ */
22
/*
33
* pthread mapping macros for win32 native thread implementation
44
*/
@@ -10,22 +10,33 @@
1010
#ifndefWIN32
1111

1212
#include<pthread.h>
13-
#defineNON_EXEC_STATICstatic
1413

1514
#else
1615

17-
#defineNON_EXEC_STATIC
16+
typedefstructpthread_mutex_t
17+
{
18+
HANDLEhandle;
19+
LONGinitlock;
20+
}pthread_mutex_t;
1821

19-
typedefHANDLEpthread_mutex_t;
2022
typedefDWORDpthread_key_t;
23+
typedefboolpthread_once_t;
2124

22-
#definePTHREAD_MUTEX_INITIALIZERINVALID_HANDLE_VALUE
25+
#definePTHREAD_MUTEX_INITIALIZER{ NULL, 0 }
26+
#definePTHREAD_ONCE_INITfalse
27+
28+
voidwin32_pthread_mutex(volatilepthread_mutex_t*mutex);
29+
voidwin32_pthread_once(volatilepthread_once_t*once,void (*fn)(void));
2330

2431
#definepthread_mutex_lock(mutex) \
25-
WaitForSingleObject(*(mutex), INFINITE);
32+
do { \
33+
if ((mutex)->handle == NULL) \
34+
win32_pthread_mutex((mutex)); \
35+
WaitForSingleObject((mutex)->handle, INFINITE); \
36+
} while(0)
2637

2738
#definepthread_mutex_unlock(mutex) \
28-
ReleaseMutex(*(mutex))
39+
ReleaseMutex((mutex)->handle)
2940

3041
#definepthread_getspecific(key) \
3142
TlsGetValue((key))
@@ -37,18 +48,11 @@ typedef DWORDpthread_key_t;
3748
#definepthread_key_create(key,destructor) \
3849
do { *(key) = TlsAlloc(); ((void)(destructor)); } while(0)
3950

40-
/* init-once functions are always called when libecpg is loaded */
41-
#definepthread_once(key,fn) \
42-
((void)0)
43-
44-
externpthread_mutex_tconnections_mutex;
45-
externpthread_mutex_tdebug_mutex;
46-
externpthread_mutex_tdebug_init_mutex;
47-
externvoidauto_mem_key_init(void);
48-
externvoidecpg_actual_connection_init(void);
49-
externvoidecpg_sqlca_key_init(void);
50-
externvoiddescriptor_key_init(void);
51-
externBOOLWINAPIDllMain(HANDLEmodule,DWORDreason,LPVOIDreserved);
51+
#definepthread_once(once,fn) \
52+
do { \
53+
if (!*(once)) \
54+
win32_pthread_once((once), (fn)); \
55+
} while(0)
5256

5357
#endif/* WIN32 */
5458

‎src/interfaces/ecpg/test/expected/thread-descriptor.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ struct sqlca_t *ECPGget_sqlca(void);
100100
#line 17 "descriptor.pgc"
101101

102102

103-
#ifdefWIN32
103+
#if defined(ENABLE_THREAD_SAFETY)&& defined(WIN32)
104104
staticunsignedSTDCALLfn(void*arg)
105105
#else
106106
staticvoid*fn(void*arg)

‎src/interfaces/ecpg/test/thread/descriptor.pgc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ EXEC SQL include sqlca;
1616
EXEC SQL whenever sqlerror sqlprint;
1717
EXEC SQL whenever not found sqlprint;
1818

19-
#ifdefWIN32
19+
#if defined(ENABLE_THREAD_SAFETY) && defined(WIN32)
2020
static unsigned STDCALL fn(void* arg)
2121
#else
2222
static void* fn(void* arg)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp