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 $ */
2
2
3
3
#define POSTGRES_ECPG_INTERNAL
4
4
#include "postgres_fe.h"
@@ -26,6 +26,11 @@ ecpg_actual_connection_init(void)
26
26
{
27
27
pthread_key_create (& actual_connection_key ,NULL );
28
28
}
29
+
30
+ void ecpg_pthreads_init (void )
31
+ {
32
+ pthread_once (& actual_connection_key_once ,ecpg_actual_connection_init );
33
+ }
29
34
#endif
30
35
31
36
static struct connection *
@@ -43,13 +48,10 @@ ecpg_get_connection_nr(const char *connection_name)
43
48
* connection and hope the user knows what they're doing (i.e. using
44
49
* their own mutex to protect that connection from concurrent accesses
45
50
*/
51
+ /* if !ret then we got the connection from TSD */
46
52
if (NULL == ret )
47
- {
48
- ECPGlog ("no TSD connection, going for global\n" );
53
+ /* no TSD connection, going for global */
49
54
ret = actual_connection ;
50
- }
51
- else
52
- ECPGlog ("got the TSD connection\n" );
53
55
#else
54
56
ret = actual_connection ;
55
57
#endif
@@ -84,13 +86,10 @@ ECPGget_connection(const char *connection_name)
84
86
* connection and hope the user knows what they're doing (i.e. using
85
87
* their own mutex to protect that connection from concurrent accesses
86
88
*/
89
+ /* if !ret then we got the connection from TSD */
87
90
if (NULL == ret )
88
- {
89
- ECPGlog ("no TSD connection here either, using global\n" );
91
+ /* no TSD connection here either, using global */
90
92
ret = actual_connection ;
91
- }
92
- else
93
- ECPGlog ("got TSD connection\n" );
94
93
#else
95
94
ret = actual_connection ;
96
95
#endif
@@ -298,6 +297,10 @@ ECPGconnect(int lineno, int c, const char *name, const char *user, const char *p
298
297
if (dbname == NULL && connection_name == NULL )
299
298
connection_name = "DEFAULT" ;
300
299
300
+ #if ENABLE_THREAD_SAFETY
301
+ ecpg_pthreads_init ();
302
+ #endif
303
+
301
304
/* check if the identifier is unique */
302
305
if (ECPGget_connection (connection_name ))
303
306
{
@@ -450,7 +453,6 @@ ECPGconnect(int lineno, int c, const char *name, const char *user, const char *p
450
453
451
454
all_connections = this ;
452
455
#ifdef ENABLE_THREAD_SAFETY
453
- pthread_once (& actual_connection_key_once ,ecpg_actual_connection_init );
454
456
pthread_setspecific (actual_connection_key ,all_connections );
455
457
#endif
456
458
actual_connection = all_connections ;