|
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 | #define POSTGRES_ECPG_INTERNAL
|
4 | 4 | #include "postgres_fe.h"
|
5 | 5 |
|
6 | 6 | #include <limits.h>
|
7 | 7 | #include <unistd.h>
|
8 | 8 | #ifdef ENABLE_THREAD_SAFETY
|
| 9 | +#ifndef WIN32 |
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 | #ifdef ENABLE_THREAD_SAFETY
|
| 65 | +#ifndef WIN32 |
61 | 66 | static pthread_key_t sqlca_key;
|
62 | 67 | static pthread_once_t sqlca_key_once = PTHREAD_ONCE_INIT;
|
63 | 68 | #else
|
| 69 | +static DWORD sqlca_key; |
| 70 | +#endif |
| 71 | +#else |
64 | 72 | static struct sqlca_t sqlca =
|
65 | 73 | {
|
66 | 74 | {
|
@@ -90,8 +98,13 @@ static struct sqlca_t sqlca =
|
90 | 98 | #endif
|
91 | 99 |
|
92 | 100 | #ifdef ENABLE_THREAD_SAFETY
|
| 101 | +#ifndef WIN32 |
93 | 102 | static pthread_mutex_t debug_mutex = PTHREAD_MUTEX_INITIALIZER;
|
94 | 103 | 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 */ |
95 | 108 | #endif
|
96 | 109 | static int simple_debug = 0;
|
97 | 110 | static FILE *debugstream = NULL;
|
@@ -138,8 +151,13 @@ ECPGget_sqlca(void)
|
138 | 151 | {
|
139 | 152 | #ifdef ENABLE_THREAD_SAFETY
|
140 | 153 | 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 |
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)
|
|
0 commit comments