|
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 $ */ |
2 | 2 |
|
3 | 3 | #definePOSTGRES_ECPG_INTERNAL
|
4 | 4 | #include"postgres_fe.h"
|
5 | 5 |
|
6 | 6 | #include<limits.h>
|
7 | 7 | #include<unistd.h>
|
8 | 8 | #ifdefENABLE_THREAD_SAFETY
|
| 9 | +#ifndefWIN32 |
9 | 10 | #include<pthread.h>
|
| 11 | +#else |
| 12 | +#include"ecpg-pthread-win32.h" |
| 13 | +#endif |
10 | 14 | #endif
|
11 | 15 | #include"ecpgtype.h"
|
12 | 16 | #include"ecpglib.h"
|
@@ -58,9 +62,13 @@ static struct sqlca_t sqlca_init =
|
58 | 62 | };
|
59 | 63 |
|
60 | 64 | #ifdefENABLE_THREAD_SAFETY
|
| 65 | +#ifndefWIN32 |
61 | 66 | staticpthread_key_tsqlca_key;
|
62 | 67 | staticpthread_once_tsqlca_key_once=PTHREAD_ONCE_INIT;
|
63 | 68 | #else
|
| 69 | +staticDWORDsqlca_key; |
| 70 | +#endif |
| 71 | +#else |
64 | 72 | staticstructsqlca_tsqlca=
|
65 | 73 | {
|
66 | 74 | {
|
@@ -90,8 +98,13 @@ static struct sqlca_t sqlca =
|
90 | 98 | #endif
|
91 | 99 |
|
92 | 100 | #ifdefENABLE_THREAD_SAFETY
|
| 101 | +#ifndefWIN32 |
93 | 102 | staticpthread_mutex_tdebug_mutex=PTHREAD_MUTEX_INITIALIZER;
|
94 | 103 | staticpthread_mutex_tdebug_init_mutex=PTHREAD_MUTEX_INITIALIZER;
|
| 104 | +#else |
| 105 | +staticHANDLEdebug_mutex=INVALID_HANDLE_VALUE; |
| 106 | +staticHANDLEdebug_init_mutex=INVALID_HANDLE_VALUE; |
| 107 | +#endif/* WIN32 */ |
95 | 108 | #endif
|
96 | 109 | staticintsimple_debug=0;
|
97 | 110 | staticFILE*debugstream=NULL;
|
@@ -138,8 +151,13 @@ ECPGget_sqlca(void)
|
138 | 151 | {
|
139 | 152 | #ifdefENABLE_THREAD_SAFETY
|
140 | 153 | structsqlca_t*sqlca;
|
141 |
| - |
| 154 | +#ifdefWIN32 |
| 155 | +staticlonghas_run=0; |
| 156 | +if (InterlockedCompareExchange(&has_run,1,0)==0) |
| 157 | +ecpg_sqlca_key_init(); |
| 158 | +#else |
142 | 159 | pthread_once(&sqlca_key_once,ecpg_sqlca_key_init);
|
| 160 | +#endif |
143 | 161 |
|
144 | 162 | sqlca=pthread_getspecific(sqlca_key);
|
145 | 163 | if (sqlca==NULL)
|
|