summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMagnus Hagander2008-05-21 14:20:48 +0000
committerMagnus Hagander2008-05-21 14:20:48 +0000
commit7de0057a37e3025a51a9aea935eb08d0a45e378c (patch)
tree672cfc62e089b845ba50c1ef9402e41677c952ef
parent95975161510a8156c2bc99f2f57eaf2aa010e9de (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.
-rw-r--r--src/interfaces/libpq/pthread-win32.c11
-rw-r--r--src/port/pthread-win32.h4
2 files changed, 9 insertions, 6 deletions
diff --git a/src/interfaces/libpq/pthread-win32.c b/src/interfaces/libpq/pthread-win32.c
index 08629ca957..0133b8c92d 100644
--- a/src/interfaces/libpq/pthread-win32.c
+++ b/src/interfaces/libpq/pthread-win32.c
@@ -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;
}
diff --git a/src/port/pthread-win32.h b/src/port/pthread-win32.h
index 71574e2a51..dbbbebf5c2 100644
--- a/src/port/pthread-win32.h
+++ b/src/port/pthread-win32.h
@@ -1,11 +1,11 @@
/*
- * $PostgreSQL:$
+ * $PostgreSQL$
*/
#ifndef __PTHREAD_H
#define __PTHREAD_H
typedef ULONG pthread_key_t;
-typedef HANDLE pthread_mutex_t;
+typedef CRITICAL_SECTION *pthread_mutex_t;
typedef int pthread_once_t;
DWORD pthread_self(void);