mirror of
https://github.com/postgres/postgres.git
synced 2025-10-24 01:29:19 +03:00
Remove --disable-thread-safety and related code.
All supported computers have either POSIX or Windows threads, and we no longer have any automated testing of --disable-thread-safety. We define a vestigial ENABLE_THREAD_SAFETY macro to 1 in ecpg_config.h in case it is useful, but we no longer test it anywhere in PostgreSQL code, and associated dead code paths are removed. The Meson and perl-based Windows build scripts never had an equivalent build option. Reviewed-by: Andres Freund <andres@anarazel.de> Reviewed-by: Peter Eisentraut <peter@eisentraut.org> Reviewed-by: Heikki Linnakangas <hlinnaka@iki.fi> Discussion: https://postgr.es/m/CA%2BhUKGLtmexrpMtxBRLCVePqV_dtWG-ZsEbyPrYc%2BNBB2TkNsw%40mail.gmail.com
This commit is contained in:
@@ -14,15 +14,12 @@
|
||||
locale_t ecpg_clocale = (locale_t) 0;
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_THREAD_SAFETY
|
||||
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;
|
||||
#endif
|
||||
static struct connection *actual_connection = NULL;
|
||||
static struct connection *all_connections = NULL;
|
||||
|
||||
#ifdef ENABLE_THREAD_SAFETY
|
||||
static void
|
||||
ecpg_actual_connection_init(void)
|
||||
{
|
||||
@@ -34,7 +31,6 @@ ecpg_pthreads_init(void)
|
||||
{
|
||||
pthread_once(&actual_connection_key_once, ecpg_actual_connection_init);
|
||||
}
|
||||
#endif
|
||||
|
||||
static struct connection *
|
||||
ecpg_get_connection_nr(const char *connection_name)
|
||||
@@ -43,7 +39,6 @@ ecpg_get_connection_nr(const char *connection_name)
|
||||
|
||||
if ((connection_name == NULL) || (strcmp(connection_name, "CURRENT") == 0))
|
||||
{
|
||||
#ifdef ENABLE_THREAD_SAFETY
|
||||
ecpg_pthreads_init(); /* ensure actual_connection_key is valid */
|
||||
|
||||
ret = pthread_getspecific(actual_connection_key);
|
||||
@@ -56,9 +51,6 @@ ecpg_get_connection_nr(const char *connection_name)
|
||||
if (ret == NULL)
|
||||
/* no TSD connection, going for global */
|
||||
ret = actual_connection;
|
||||
#else
|
||||
ret = actual_connection;
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -82,7 +74,6 @@ ecpg_get_connection(const char *connection_name)
|
||||
|
||||
if ((connection_name == NULL) || (strcmp(connection_name, "CURRENT") == 0))
|
||||
{
|
||||
#ifdef ENABLE_THREAD_SAFETY
|
||||
ecpg_pthreads_init(); /* ensure actual_connection_key is valid */
|
||||
|
||||
ret = pthread_getspecific(actual_connection_key);
|
||||
@@ -95,21 +86,14 @@ ecpg_get_connection(const char *connection_name)
|
||||
if (ret == NULL)
|
||||
/* no TSD connection here either, using global */
|
||||
ret = actual_connection;
|
||||
#else
|
||||
ret = actual_connection;
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef ENABLE_THREAD_SAFETY
|
||||
pthread_mutex_lock(&connections_mutex);
|
||||
#endif
|
||||
|
||||
ret = ecpg_get_connection_nr(connection_name);
|
||||
|
||||
#ifdef ENABLE_THREAD_SAFETY
|
||||
pthread_mutex_unlock(&connections_mutex);
|
||||
#endif
|
||||
}
|
||||
|
||||
return ret;
|
||||
@@ -143,10 +127,8 @@ ecpg_finish(struct connection *act)
|
||||
con->next = act->next;
|
||||
}
|
||||
|
||||
#ifdef ENABLE_THREAD_SAFETY
|
||||
if (pthread_getspecific(actual_connection_key) == act)
|
||||
pthread_setspecific(actual_connection_key, all_connections);
|
||||
#endif
|
||||
if (actual_connection == act)
|
||||
actual_connection = all_connections;
|
||||
|
||||
@@ -212,11 +194,7 @@ ECPGsetconn(int lineno, const char *connection_name)
|
||||
if (!ecpg_init(con, connection_name, lineno))
|
||||
return false;
|
||||
|
||||
#ifdef ENABLE_THREAD_SAFETY
|
||||
pthread_setspecific(actual_connection_key, con);
|
||||
#else
|
||||
actual_connection = con;
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -326,9 +304,7 @@ ECPGconnect(int lineno, int c, const char *name, const char *user, const char *p
|
||||
if (dbname == NULL && connection_name == NULL)
|
||||
connection_name = "DEFAULT";
|
||||
|
||||
#if ENABLE_THREAD_SAFETY
|
||||
ecpg_pthreads_init();
|
||||
#endif
|
||||
|
||||
/* check if the identifier is unique */
|
||||
if (ecpg_get_connection(connection_name))
|
||||
@@ -505,9 +481,7 @@ ECPGconnect(int lineno, int c, const char *name, const char *user, const char *p
|
||||
}
|
||||
|
||||
/* add connection to our list */
|
||||
#ifdef ENABLE_THREAD_SAFETY
|
||||
pthread_mutex_lock(&connections_mutex);
|
||||
#endif
|
||||
|
||||
/*
|
||||
* ... but first, make certain we have created ecpg_clocale. Rely on
|
||||
@@ -519,9 +493,7 @@ ECPGconnect(int lineno, int c, const char *name, const char *user, const char *p
|
||||
ecpg_clocale = newlocale(LC_NUMERIC_MASK, "C", (locale_t) 0);
|
||||
if (!ecpg_clocale)
|
||||
{
|
||||
#ifdef ENABLE_THREAD_SAFETY
|
||||
pthread_mutex_unlock(&connections_mutex);
|
||||
#endif
|
||||
ecpg_raise(lineno, ECPG_OUT_OF_MEMORY,
|
||||
ECPG_SQLSTATE_ECPG_OUT_OF_MEMORY, NULL);
|
||||
if (host)
|
||||
@@ -558,9 +530,7 @@ ECPGconnect(int lineno, int c, const char *name, const char *user, const char *p
|
||||
this->next = all_connections;
|
||||
|
||||
all_connections = this;
|
||||
#ifdef ENABLE_THREAD_SAFETY
|
||||
pthread_setspecific(actual_connection_key, all_connections);
|
||||
#endif
|
||||
actual_connection = all_connections;
|
||||
|
||||
ecpg_log("ECPGconnect: opening database %s on %s port %s %s%s %s%s\n",
|
||||
@@ -678,9 +648,7 @@ ECPGconnect(int lineno, int c, const char *name, const char *user, const char *p
|
||||
ecpg_log("ECPGconnect: %s", errmsg);
|
||||
|
||||
ecpg_finish(this);
|
||||
#ifdef ENABLE_THREAD_SAFETY
|
||||
pthread_mutex_unlock(&connections_mutex);
|
||||
#endif
|
||||
|
||||
ecpg_raise(lineno, ECPG_CONNECT, ECPG_SQLSTATE_SQLCLIENT_UNABLE_TO_ESTABLISH_SQLCONNECTION, db);
|
||||
if (realname)
|
||||
@@ -692,9 +660,7 @@ ECPGconnect(int lineno, int c, const char *name, const char *user, const char *p
|
||||
if (realname)
|
||||
ecpg_free(realname);
|
||||
|
||||
#ifdef ENABLE_THREAD_SAFETY
|
||||
pthread_mutex_unlock(&connections_mutex);
|
||||
#endif
|
||||
|
||||
this->autocommit = autocommit;
|
||||
|
||||
@@ -716,9 +682,7 @@ ECPGdisconnect(int lineno, const char *connection_name)
|
||||
return false;
|
||||
}
|
||||
|
||||
#ifdef ENABLE_THREAD_SAFETY
|
||||
pthread_mutex_lock(&connections_mutex);
|
||||
#endif
|
||||
|
||||
if (strcmp(connection_name, "ALL") == 0)
|
||||
{
|
||||
@@ -737,18 +701,14 @@ ECPGdisconnect(int lineno, const char *connection_name)
|
||||
|
||||
if (!ecpg_init(con, connection_name, lineno))
|
||||
{
|
||||
#ifdef ENABLE_THREAD_SAFETY
|
||||
pthread_mutex_unlock(&connections_mutex);
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
else
|
||||
ecpg_finish(con);
|
||||
}
|
||||
|
||||
#ifdef ENABLE_THREAD_SAFETY
|
||||
pthread_mutex_unlock(&connections_mutex);
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -19,7 +19,6 @@
|
||||
static void descriptor_free(struct descriptor *desc);
|
||||
|
||||
/* We manage descriptors separately for each thread. */
|
||||
#ifdef ENABLE_THREAD_SAFETY
|
||||
static pthread_key_t descriptor_key;
|
||||
static pthread_once_t descriptor_once = PTHREAD_ONCE_INIT;
|
||||
|
||||
@@ -49,12 +48,6 @@ set_descriptors(struct descriptor *value)
|
||||
{
|
||||
pthread_setspecific(descriptor_key, value);
|
||||
}
|
||||
#else
|
||||
static struct descriptor *all_descriptors = NULL;
|
||||
|
||||
#define get_descriptors() (all_descriptors)
|
||||
#define set_descriptors(value) do { all_descriptors = (value); } while(0)
|
||||
#endif
|
||||
|
||||
/* old internal convenience function that might go away later */
|
||||
static PGresult *
|
||||
@@ -782,8 +775,6 @@ ECPGdeallocate_desc(int line, const char *name)
|
||||
return false;
|
||||
}
|
||||
|
||||
#ifdef ENABLE_THREAD_SAFETY
|
||||
|
||||
/* Deallocate all descriptors in the list */
|
||||
static void
|
||||
descriptor_deallocate_all(struct descriptor *list)
|
||||
@@ -796,7 +787,6 @@ descriptor_deallocate_all(struct descriptor *list)
|
||||
list = next;
|
||||
}
|
||||
}
|
||||
#endif /* ENABLE_THREAD_SAFETY */
|
||||
|
||||
bool
|
||||
ECPGallocate_desc(int line, const char *name)
|
||||
|
||||
@@ -169,9 +169,7 @@ bool ecpg_get_data(const PGresult *, int, int, int, enum ECPGttype type,
|
||||
enum ECPGttype, char *, char *, long, long, long,
|
||||
enum ARRAY_TYPE, enum COMPAT_MODE, bool);
|
||||
|
||||
#ifdef ENABLE_THREAD_SAFETY
|
||||
void ecpg_pthreads_init(void);
|
||||
#endif
|
||||
struct connection *ecpg_get_connection(const char *connection_name);
|
||||
char *ecpg_alloc(long size, int lineno);
|
||||
char *ecpg_auto_alloc(long size, int lineno);
|
||||
|
||||
@@ -1961,9 +1961,7 @@ ecpg_do_prologue(int lineno, const int compat, const int force_indicator,
|
||||
return false;
|
||||
}
|
||||
|
||||
#ifdef ENABLE_THREAD_SAFETY
|
||||
ecpg_pthreads_init();
|
||||
#endif
|
||||
|
||||
con = ecpg_get_connection(connection_name);
|
||||
|
||||
|
||||
@@ -68,7 +68,6 @@ struct auto_mem
|
||||
struct auto_mem *next;
|
||||
};
|
||||
|
||||
#ifdef ENABLE_THREAD_SAFETY
|
||||
static pthread_key_t auto_mem_key;
|
||||
static pthread_once_t auto_mem_once = PTHREAD_ONCE_INIT;
|
||||
|
||||
@@ -97,12 +96,6 @@ set_auto_allocs(struct auto_mem *am)
|
||||
{
|
||||
pthread_setspecific(auto_mem_key, am);
|
||||
}
|
||||
#else
|
||||
static struct auto_mem *auto_allocs = NULL;
|
||||
|
||||
#define get_auto_allocs() (auto_allocs)
|
||||
#define set_auto_allocs(am) do { auto_allocs = (am); } while(0)
|
||||
#endif
|
||||
|
||||
char *
|
||||
ecpg_auto_alloc(long size, int lineno)
|
||||
|
||||
@@ -55,42 +55,11 @@ static struct sqlca_t sqlca_init =
|
||||
}
|
||||
};
|
||||
|
||||
#ifdef ENABLE_THREAD_SAFETY
|
||||
static pthread_key_t sqlca_key;
|
||||
static pthread_once_t sqlca_key_once = PTHREAD_ONCE_INIT;
|
||||
#else
|
||||
static struct sqlca_t sqlca =
|
||||
{
|
||||
{
|
||||
'S', 'Q', 'L', 'C', 'A', ' ', ' ', ' '
|
||||
},
|
||||
sizeof(struct sqlca_t),
|
||||
0,
|
||||
{
|
||||
0,
|
||||
{
|
||||
0
|
||||
}
|
||||
},
|
||||
{
|
||||
'N', 'O', 'T', ' ', 'S', 'E', 'T', ' '
|
||||
},
|
||||
{
|
||||
0, 0, 0, 0, 0, 0
|
||||
},
|
||||
{
|
||||
0, 0, 0, 0, 0, 0, 0, 0
|
||||
},
|
||||
{
|
||||
'0', '0', '0', '0', '0'
|
||||
}
|
||||
};
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_THREAD_SAFETY
|
||||
static pthread_mutex_t debug_mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
static pthread_mutex_t debug_init_mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
#endif
|
||||
static int simple_debug = 0;
|
||||
static FILE *debugstream = NULL;
|
||||
|
||||
@@ -123,7 +92,6 @@ ecpg_init(const struct connection *con, const char *connection_name, const int l
|
||||
return true;
|
||||
}
|
||||
|
||||
#ifdef ENABLE_THREAD_SAFETY
|
||||
static void
|
||||
ecpg_sqlca_key_destructor(void *arg)
|
||||
{
|
||||
@@ -135,12 +103,10 @@ ecpg_sqlca_key_init(void)
|
||||
{
|
||||
pthread_key_create(&sqlca_key, ecpg_sqlca_key_destructor);
|
||||
}
|
||||
#endif
|
||||
|
||||
struct sqlca_t *
|
||||
ECPGget_sqlca(void)
|
||||
{
|
||||
#ifdef ENABLE_THREAD_SAFETY
|
||||
struct sqlca_t *sqlca;
|
||||
|
||||
pthread_once(&sqlca_key_once, ecpg_sqlca_key_init);
|
||||
@@ -155,9 +121,6 @@ ECPGget_sqlca(void)
|
||||
pthread_setspecific(sqlca_key, sqlca);
|
||||
}
|
||||
return sqlca;
|
||||
#else
|
||||
return &sqlca;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool
|
||||
@@ -240,9 +203,7 @@ ECPGtrans(int lineno, const char *connection_name, const char *transaction)
|
||||
void
|
||||
ECPGdebug(int n, FILE *dbgs)
|
||||
{
|
||||
#ifdef ENABLE_THREAD_SAFETY
|
||||
pthread_mutex_lock(&debug_init_mutex);
|
||||
#endif
|
||||
|
||||
if (n > 100)
|
||||
{
|
||||
@@ -256,9 +217,7 @@ ECPGdebug(int n, FILE *dbgs)
|
||||
|
||||
ecpg_log("ECPGdebug: set to %d\n", simple_debug);
|
||||
|
||||
#ifdef ENABLE_THREAD_SAFETY
|
||||
pthread_mutex_unlock(&debug_init_mutex);
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
@@ -290,9 +249,7 @@ ecpg_log(const char *format,...)
|
||||
else
|
||||
snprintf(fmt, bufsize, "[%d]: %s", (int) getpid(), intl_format);
|
||||
|
||||
#ifdef ENABLE_THREAD_SAFETY
|
||||
pthread_mutex_lock(&debug_mutex);
|
||||
#endif
|
||||
|
||||
va_start(ap, format);
|
||||
vfprintf(debugstream, fmt, ap);
|
||||
@@ -307,9 +264,7 @@ ecpg_log(const char *format,...)
|
||||
|
||||
fflush(debugstream);
|
||||
|
||||
#ifdef ENABLE_THREAD_SAFETY
|
||||
pthread_mutex_unlock(&debug_mutex);
|
||||
#endif
|
||||
|
||||
free(fmt);
|
||||
}
|
||||
@@ -451,7 +406,6 @@ ECPGis_noind_null(enum ECPGttype type, const void *ptr)
|
||||
}
|
||||
|
||||
#ifdef WIN32
|
||||
#ifdef ENABLE_THREAD_SAFETY
|
||||
|
||||
void
|
||||
win32_pthread_mutex(volatile pthread_mutex_t *mutex)
|
||||
@@ -482,7 +436,6 @@ win32_pthread_once(volatile pthread_once_t *once, void (*fn) (void))
|
||||
pthread_mutex_unlock(&win32_pthread_once_lock);
|
||||
}
|
||||
}
|
||||
#endif /* ENABLE_THREAD_SAFETY */
|
||||
#endif /* WIN32 */
|
||||
|
||||
#ifdef ENABLE_NLS
|
||||
|
||||
Reference in New Issue
Block a user