1
0
mirror of https://github.com/postgres/postgres.git synced 2025-08-21 10:42:50 +03:00

- Added patch by Magnus Hagander <magnus@hagander.net> to use native

win32 threads.
- Fixed regression tests to run threading tests.
This commit is contained in:
Michael Meskes
2007-03-29 12:02:24 +00:00
parent fba8113c1b
commit ddcb5bbf76
17 changed files with 170 additions and 152 deletions

View File

@@ -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

View File

@@ -1,4 +1,4 @@
/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/execute.c,v 1.64 2007/02/11 15:18:17 meskes Exp $ */
/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/execute.c,v 1.65 2007/03/29 12:02:24 meskes Exp $ */
/*
* The aim is to get a simpler inteface to the database routines.
@@ -39,7 +39,6 @@ static char *
quote_postgres(char *arg, bool quote, int lineno)
{
char *res;
int error;
size_t length;
size_t escaped_len;
size_t buffer_len;
@@ -58,13 +57,7 @@ quote_postgres(char *arg, bool quote, int lineno)
if (!res)
return (res);
error = 0;
escaped_len = PQescapeString(res+1, arg, buffer_len);
if (error)
{
ECPGfree(res);
return NULL;
}
if (length == escaped_len)
{
res[0] = res[escaped_len+1] = '\'';

View File

@@ -1,4 +1,4 @@
/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/extern.h,v 1.22 2007/01/25 16:45:25 meskes Exp $ */
/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/extern.h,v 1.23 2007/03/29 12:02:24 meskes Exp $ */
#ifndef _ECPG_LIB_EXTERN_H
#define _ECPG_LIB_EXTERN_H
@@ -6,6 +6,7 @@
#include "postgres_fe.h"
#include "libpq-fe.h"
#include "sqlca.h"
#include "ecpg_config.h"
enum COMPAT_MODE
{

View File

@@ -1,4 +1,4 @@
/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/misc.c,v 1.34 2007/01/12 10:00:13 meskes Exp $ */
/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/misc.c,v 1.35 2007/03/29 12:02:24 meskes Exp $ */
#define POSTGRES_ECPG_INTERNAL
#include "postgres_fe.h"
@@ -6,7 +6,11 @@
#include <limits.h>
#include <unistd.h>
#ifdef ENABLE_THREAD_SAFETY
#ifndef WIN32
#include <pthread.h>
#else
#include "ecpg-pthread-win32.h"
#endif
#endif
#include "ecpgtype.h"
#include "ecpglib.h"
@@ -58,9 +62,13 @@ static struct sqlca_t sqlca_init =
};
#ifdef ENABLE_THREAD_SAFETY
#ifndef WIN32
static pthread_key_t sqlca_key;
static pthread_once_t sqlca_key_once = PTHREAD_ONCE_INIT;
#else
static DWORD sqlca_key;
#endif
#else
static struct sqlca_t sqlca =
{
{
@@ -90,8 +98,13 @@ static struct sqlca_t sqlca =
#endif
#ifdef ENABLE_THREAD_SAFETY
#ifndef WIN32
static pthread_mutex_t debug_mutex = PTHREAD_MUTEX_INITIALIZER;
static pthread_mutex_t debug_init_mutex = PTHREAD_MUTEX_INITIALIZER;
#else
static HANDLE debug_mutex = INVALID_HANDLE_VALUE;
static HANDLE debug_init_mutex = INVALID_HANDLE_VALUE;
#endif /* WIN32 */
#endif
static int simple_debug = 0;
static FILE *debugstream = NULL;
@@ -138,8 +151,13 @@ ECPGget_sqlca(void)
{
#ifdef ENABLE_THREAD_SAFETY
struct sqlca_t *sqlca;
#ifdef WIN32
static long has_run = 0;
if (InterlockedCompareExchange(&has_run, 1, 0) == 0)
ecpg_sqlca_key_init();
#else
pthread_once(&sqlca_key_once, ecpg_sqlca_key_init);
#endif
sqlca = pthread_getspecific(sqlca_key);
if (sqlca == NULL)