diff options
| author | Michael Meskes <meskes@postgresql.org> | 2007-03-29 12:02:24 +0000 |
|---|---|---|
| committer | Michael Meskes <meskes@postgresql.org> | 2007-03-29 12:02:24 +0000 |
| commit | ddcb5bbf76dd991b5a7024bc3d4e212b97d27936 (patch) | |
| tree | 0b6247677e8a9cf3ea60df6ae5474225f4e11ecb /src/interfaces/ecpg/ecpglib | |
| parent | fba8113c1b74b9508cf2e6b7a18b0fb3637d9ba0 (diff) | |
| download | postgresql-ddcb5bbf76dd991b5a7024bc3d4e212b97d27936.tar.gz | |
- 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')
| -rw-r--r-- | src/interfaces/ecpg/ecpglib/connect.c | 17 | ||||
| -rw-r--r-- | src/interfaces/ecpg/ecpglib/execute.c | 9 | ||||
| -rw-r--r-- | src/interfaces/ecpg/ecpglib/extern.h | 3 | ||||
| -rw-r--r-- | src/interfaces/ecpg/ecpglib/misc.c | 22 |
4 files changed, 39 insertions, 12 deletions
diff --git a/src/interfaces/ecpg/ecpglib/connect.c b/src/interfaces/ecpg/ecpglib/connect.c index 92c7ba8cc8..650c4e503c 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 diff --git a/src/interfaces/ecpg/ecpglib/execute.c b/src/interfaces/ecpg/ecpglib/execute.c index bf72920bdc..e1326d3e3e 100644 --- a/src/interfaces/ecpg/ecpglib/execute.c +++ b/src/interfaces/ecpg/ecpglib/execute.c @@ -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] = '\''; diff --git a/src/interfaces/ecpg/ecpglib/extern.h b/src/interfaces/ecpg/ecpglib/extern.h index 45a182a0d4..0fb83f4495 100644 --- a/src/interfaces/ecpg/ecpglib/extern.h +++ b/src/interfaces/ecpg/ecpglib/extern.h @@ -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 { diff --git a/src/interfaces/ecpg/ecpglib/misc.c b/src/interfaces/ecpg/ecpglib/misc.c index 4273819e79..47d924fac8 100644 --- a/src/interfaces/ecpg/ecpglib/misc.c +++ b/src/interfaces/ecpg/ecpglib/misc.c @@ -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) |
