aboutsummaryrefslogtreecommitdiff
path: root/src/interfaces/ecpg/ecpglib/connect.c
diff options
context:
space:
mode:
authorMichael Meskes <meskes@postgresql.org>2007-03-29 12:02:24 +0000
committerMichael Meskes <meskes@postgresql.org>2007-03-29 12:02:24 +0000
commitddcb5bbf76dd991b5a7024bc3d4e212b97d27936 (patch)
tree0b6247677e8a9cf3ea60df6ae5474225f4e11ecb /src/interfaces/ecpg/ecpglib/connect.c
parentfba8113c1b74b9508cf2e6b7a18b0fb3637d9ba0 (diff)
downloadpostgresql-ddcb5bbf76dd991b5a7024bc3d4e212b97d27936.tar.gz
postgresql-ddcb5bbf76dd991b5a7024bc3d4e212b97d27936.zip
- Added patch by Magnus Hagander <magnus@hagander.net> to use native
win32 threads. - Fixed regression tests to run threading tests.
Diffstat (limited to 'src/interfaces/ecpg/ecpglib/connect.c')
-rw-r--r--src/interfaces/ecpg/ecpglib/connect.c17
1 files changed, 16 insertions, 1 deletions
diff --git a/src/interfaces/ecpg/ecpglib/connect.c b/src/interfaces/ecpg/ecpglib/connect.c
index 92c7ba8cc88..650c4e503c0 100644
--- a/src/interfaces/ecpg/ecpglib/connect.c
+++ b/src/interfaces/ecpg/ecpglib/connect.c
@@ -1,10 +1,14 @@
-/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/connect.c,v 1.40 2007/03/17 19:25:22 meskes Exp $ */
+/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/connect.c,v 1.41 2007/03/29 12:02:24 meskes Exp $ */
#define POSTGRES_ECPG_INTERNAL
#include "postgres_fe.h"
#ifdef ENABLE_THREAD_SAFETY
+#ifndef WIN32
#include <pthread.h>
+#else
+#include "ecpg-pthread-win32.h"
+#endif
#endif
#include "ecpgtype.h"
#include "ecpglib.h"
@@ -13,9 +17,14 @@
#include "sqlca.h"
#ifdef ENABLE_THREAD_SAFETY
+#ifndef WIN32
static pthread_mutex_t connections_mutex = PTHREAD_MUTEX_INITIALIZER;
static pthread_key_t actual_connection_key;
static pthread_once_t actual_connection_key_once = PTHREAD_ONCE_INIT;
+#else
+static HANDLE connections_mutex = INVALID_HANDLE_VALUE;
+static DWORD actual_connection_key;
+#endif /* WIN32 */
#endif
static struct connection *actual_connection = NULL;
static struct connection *all_connections = NULL;
@@ -30,7 +39,13 @@ ecpg_actual_connection_init(void)
void
ecpg_pthreads_init(void)
{
+#ifndef WIN32
pthread_once(&actual_connection_key_once, ecpg_actual_connection_init);
+#else
+ static long has_run = 0;
+ if (InterlockedCompareExchange(&has_run, 1, 0) == 0)
+ ecpg_actual_connection_init();
+#endif
}
#endif