Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf4c5e06

Browse files
committed
> 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
1 parenta29d26a commitf4c5e06

File tree

2 files changed

+22
-10
lines changed

2 files changed

+22
-10
lines changed

‎src/interfaces/libpq/fe-connect.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-connect.c,v 1.277 2004/07/12 14:16:28 momjian Exp $
11+
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-connect.c,v 1.278 2004/07/12 14:23:28 momjian Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -3193,10 +3193,16 @@ default_threadlock(int acquire)
31933193
#ifndefWIN32
31943194
staticpthread_mutex_tsinglethread_lock=PTHREAD_MUTEX_INITIALIZER;
31953195
#else
3196-
staticpthread_mutex_tsinglethread_lock;
3197-
staticlongmutex_initialized=0;
3198-
if (!InterlockedExchange(&mutex_initialized,1L))
3199-
pthread_mutex_init(&singlethread_lock,NULL);
3196+
staticpthread_mutex_tsinglethread_lock=NULL;
3197+
staticlongmutex_initlock=0;
3198+
3199+
if (singlethread_lock==NULL) {
3200+
while(InterlockedExchange(&mutex_initlock,1)==1)
3201+
/* loop, another thread own the lock */ ;
3202+
if (singlethread_lock==NULL)
3203+
pthread_mutex_init(&singlethread_lock,NULL);
3204+
InterlockedExchange(&mutex_initlock,0);
3205+
}
32003206
#endif
32013207
if (acquire)
32023208
pthread_mutex_lock(&singlethread_lock);

‎src/interfaces/libpq/fe-secure.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*
1212
*
1313
* IDENTIFICATION
14-
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-secure.c,v 1.44 2004/07/12 14:16:28 momjian Exp $
14+
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-secure.c,v 1.45 2004/07/12 14:23:28 momjian Exp $
1515
*
1616
* NOTES
1717
* The client *requires* a valid server certificate. Since
@@ -867,10 +867,16 @@ init_ssl_system(PGconn *conn)
867867
#ifndefWIN32
868868
staticpthread_mutex_tinit_mutex=PTHREAD_MUTEX_INITIALIZER;
869869
#else
870-
staticpthread_mutex_tinit_mutex;
871-
staticlongmutex_initialized=0L;
872-
if (!InterlockedExchange(&mutex_initialized,1L))
873-
pthread_mutex_init(&init_mutex,NULL);
870+
staticpthread_mutex_tinit_mutex=NULL;
871+
staticlongmutex_initlock=0;
872+
873+
if (init_mutex==NULL) {
874+
while(InterlockedExchange(&mutex_initlock,1)==1)
875+
/* loop, another thread own the lock */ ;
876+
if (init_mutex==NULL)
877+
pthread_mutex_init(&init_mutex,NULL);
878+
InterlockedExchange(&mutex_initlock,0);
879+
}
874880
#endif
875881
pthread_mutex_lock(&init_mutex);
876882

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp