1- /* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/connect.c,v 1.31 2006/07/28 10:10:42 meskes Exp $ */
1+ /* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/connect.c,v 1.32 2006/08/02 13:43:22 meskes Exp $ */
22
33#define POSTGRES_ECPG_INTERNAL
44#include "postgres_fe.h"
@@ -26,6 +26,11 @@ ecpg_actual_connection_init(void)
2626{
2727pthread_key_create (& actual_connection_key ,NULL );
2828}
29+
30+ void ecpg_pthreads_init (void )
31+ {
32+ pthread_once (& actual_connection_key_once ,ecpg_actual_connection_init );
33+ }
2934#endif
3035
3136static struct connection *
@@ -43,13 +48,10 @@ ecpg_get_connection_nr(const char *connection_name)
4348 * connection and hope the user knows what they're doing (i.e. using
4449 * their own mutex to protect that connection from concurrent accesses
4550 */
51+ /* if !ret then we got the connection from TSD */
4652if (NULL == ret )
47- {
48- ECPGlog ("no TSD connection, going for global\n" );
53+ /* no TSD connection, going for global */
4954ret = actual_connection ;
50- }
51- else
52- ECPGlog ("got the TSD connection\n" );
5355#else
5456ret = actual_connection ;
5557#endif
@@ -84,13 +86,10 @@ ECPGget_connection(const char *connection_name)
8486 * connection and hope the user knows what they're doing (i.e. using
8587 * their own mutex to protect that connection from concurrent accesses
8688 */
89+ /* if !ret then we got the connection from TSD */
8790if (NULL == ret )
88- {
89- ECPGlog ("no TSD connection here either, using global\n" );
91+ /* no TSD connection here either, using global */
9092ret = actual_connection ;
91- }
92- else
93- ECPGlog ("got TSD connection\n" );
9493#else
9594ret = actual_connection ;
9695#endif
@@ -298,6 +297,10 @@ ECPGconnect(int lineno, int c, const char *name, const char *user, const char *p
298297if (dbname == NULL && connection_name == NULL )
299298connection_name = "DEFAULT" ;
300299
300+ #if ENABLE_THREAD_SAFETY
301+ ecpg_pthreads_init ();
302+ #endif
303+
301304/* check if the identifier is unique */
302305if (ECPGget_connection (connection_name ))
303306{
@@ -450,7 +453,6 @@ ECPGconnect(int lineno, int c, const char *name, const char *user, const char *p
450453
451454all_connections = this ;
452455#ifdef ENABLE_THREAD_SAFETY
453- pthread_once (& actual_connection_key_once ,ecpg_actual_connection_init );
454456pthread_setspecific (actual_connection_key ,all_connections );
455457#endif
456458actual_connection = all_connections ;