diff options
author | Magnus Hagander <magnus@hagander.net> | 2008-05-21 14:20:48 +0000 |
---|---|---|
committer | Magnus Hagander <magnus@hagander.net> | 2008-05-21 14:20:48 +0000 |
commit | 206378e4ab02d8ea989c9b26103756b9a8be618a (patch) | |
tree | 0e343c35b6b568d4d690e98016684f7c1cfe8c69 /src/interfaces/libpq/pthread-win32.c | |
parent | 763c4866a2771a4e5c693cbd43fa349980828fab (diff) |
Use CRITICAL_SECTION instead of Mutexes for thread-locking in libpq on
Windows, for better performance.
Per suggestion from Andrew Chernow, but not his patch since the underlying
code was changed to deal with return values.
Diffstat (limited to 'src/interfaces/libpq/pthread-win32.c')
-rw-r--r-- | src/interfaces/libpq/pthread-win32.c | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/src/interfaces/libpq/pthread-win32.c b/src/interfaces/libpq/pthread-win32.c index 1fdd264171c..0f9b3a64889 100644 --- a/src/interfaces/libpq/pthread-win32.c +++ b/src/interfaces/libpq/pthread-win32.c @@ -5,7 +5,7 @@ * * Copyright (c) 2004-2008, PostgreSQL Global Development Group * IDENTIFICATION -* $PostgreSQL: pgsql/src/interfaces/libpq/pthread-win32.c,v 1.16 2008/05/16 18:30:53 mha Exp $ +* $PostgreSQL: pgsql/src/interfaces/libpq/pthread-win32.c,v 1.17 2008/05/21 14:20:48 mha Exp $ * *------------------------------------------------------------------------- */ @@ -35,24 +35,27 @@ pthread_getspecific(pthread_key_t key) int pthread_mutex_init(pthread_mutex_t *mp, void *attr) { - *mp = CreateMutex(0, 0, 0); - if (*mp == NULL) + *mp = (CRITICAL_SECTION *)malloc(sizeof(CRITICAL_SECTION)); + if (!*mp) return 1; + InitializeCriticalSection(*mp); return 0; } int pthread_mutex_lock(pthread_mutex_t *mp) { - if (WaitForSingleObject(*mp, INFINITE) != WAIT_OBJECT_0) + if (!*mp) return 1; + EnterCriticalSection(*mp); return 0; } int pthread_mutex_unlock(pthread_mutex_t *mp) { - if (!ReleaseMutex(*mp)) + if (!*mp) return 1; + LeaveCriticalSection(*mp); return 0; } |