mirror of
https://github.com/postgres/postgres.git
synced 2025-04-27 22:56:53 +03:00
> win32 doesn't support a static initializer for mutexes, thus the first
> user must initialize the lock. The problem are concurrent "first" users > - the pthread_mutex_t initialization must be synchronized. > The current implementation is broken, the attached patches fixes that: > mutex_initlock is a spinlock. If the pthread_mutex_t mutex is not > initialized, then the spinlock is acquired, if the pthread_mutex_t is > initialized if it's not yet initialized and then the spinlock is dropped. Manfred Spraul
This commit is contained in:
parent
a29d26a3cd
commit
f4c5e06edf
@ -8,7 +8,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-connect.c,v 1.277 2004/07/12 14:16:28 momjian Exp $
|
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-connect.c,v 1.278 2004/07/12 14:23:28 momjian Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -3193,10 +3193,16 @@ default_threadlock(int acquire)
|
|||||||
#ifndef WIN32
|
#ifndef WIN32
|
||||||
static pthread_mutex_t singlethread_lock = PTHREAD_MUTEX_INITIALIZER;
|
static pthread_mutex_t singlethread_lock = PTHREAD_MUTEX_INITIALIZER;
|
||||||
#else
|
#else
|
||||||
static pthread_mutex_t singlethread_lock;
|
static pthread_mutex_t singlethread_lock = NULL;
|
||||||
static long mutex_initialized = 0;
|
static long mutex_initlock = 0;
|
||||||
if (!InterlockedExchange(&mutex_initialized, 1L))
|
|
||||||
|
if (singlethread_lock == NULL) {
|
||||||
|
while(InterlockedExchange(&mutex_initlock, 1) == 1)
|
||||||
|
/* loop, another thread own the lock */ ;
|
||||||
|
if (singlethread_lock == NULL)
|
||||||
pthread_mutex_init(&singlethread_lock, NULL);
|
pthread_mutex_init(&singlethread_lock, NULL);
|
||||||
|
InterlockedExchange(&mutex_initlock,0);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
if (acquire)
|
if (acquire)
|
||||||
pthread_mutex_lock(&singlethread_lock);
|
pthread_mutex_lock(&singlethread_lock);
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-secure.c,v 1.44 2004/07/12 14:16:28 momjian Exp $
|
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-secure.c,v 1.45 2004/07/12 14:23:28 momjian Exp $
|
||||||
*
|
*
|
||||||
* NOTES
|
* NOTES
|
||||||
* The client *requires* a valid server certificate. Since
|
* The client *requires* a valid server certificate. Since
|
||||||
@ -867,10 +867,16 @@ init_ssl_system(PGconn *conn)
|
|||||||
#ifndef WIN32
|
#ifndef WIN32
|
||||||
static pthread_mutex_t init_mutex = PTHREAD_MUTEX_INITIALIZER;
|
static pthread_mutex_t init_mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||||
#else
|
#else
|
||||||
static pthread_mutex_t init_mutex;
|
static pthread_mutex_t init_mutex = NULL;
|
||||||
static long mutex_initialized = 0L;
|
static long mutex_initlock = 0;
|
||||||
if (!InterlockedExchange(&mutex_initialized, 1L))
|
|
||||||
|
if (init_mutex == NULL) {
|
||||||
|
while(InterlockedExchange(&mutex_initlock, 1) == 1)
|
||||||
|
/* loop, another thread own the lock */ ;
|
||||||
|
if (init_mutex == NULL)
|
||||||
pthread_mutex_init(&init_mutex, NULL);
|
pthread_mutex_init(&init_mutex, NULL);
|
||||||
|
InterlockedExchange(&mutex_initlock,0);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
pthread_mutex_lock(&init_mutex);
|
pthread_mutex_lock(&init_mutex);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user