Skip to content

Commit 206378e

Browse files
committed
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.
1 parent 763c486 commit 206378e

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

src/interfaces/libpq/pthread-win32.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*
66
* Copyright (c) 2004-2008, PostgreSQL Global Development Group
77
* IDENTIFICATION
8-
* $PostgreSQL: pgsql/src/interfaces/libpq/pthread-win32.c,v 1.16 2008/05/16 18:30:53 mha Exp $
8+
* $PostgreSQL: pgsql/src/interfaces/libpq/pthread-win32.c,v 1.17 2008/05/21 14:20:48 mha Exp $
99
*
1010
*-------------------------------------------------------------------------
1111
*/
@@ -35,24 +35,27 @@ pthread_getspecific(pthread_key_t key)
3535
int
3636
pthread_mutex_init(pthread_mutex_t *mp, void *attr)
3737
{
38-
*mp = CreateMutex(0, 0, 0);
39-
if (*mp == NULL)
38+
*mp = (CRITICAL_SECTION *)malloc(sizeof(CRITICAL_SECTION));
39+
if (!*mp)
4040
return 1;
41+
InitializeCriticalSection(*mp);
4142
return 0;
4243
}
4344

4445
int
4546
pthread_mutex_lock(pthread_mutex_t *mp)
4647
{
47-
if (WaitForSingleObject(*mp, INFINITE) != WAIT_OBJECT_0)
48+
if (!*mp)
4849
return 1;
50+
EnterCriticalSection(*mp);
4951
return 0;
5052
}
5153

5254
int
5355
pthread_mutex_unlock(pthread_mutex_t *mp)
5456
{
55-
if (!ReleaseMutex(*mp))
57+
if (!*mp)
5658
return 1;
59+
LeaveCriticalSection(*mp);
5760
return 0;
5861
}

src/port/pthread-win32.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/*
2-
* $PostgreSQL: pgsql/src/port/pthread-win32.h,v 1.4 2008/05/17 01:28:25 adunstan Exp $
2+
* $PostgreSQL: pgsql/src/port/pthread-win32.h,v 1.5 2008/05/21 14:20:48 mha Exp $
33
*/
44
#ifndef __PTHREAD_H
55
#define __PTHREAD_H
66

77
typedef ULONG pthread_key_t;
8-
typedef HANDLE pthread_mutex_t;
8+
typedef CRITICAL_SECTION *pthread_mutex_t;
99
typedef int pthread_once_t;
1010

1111
DWORD pthread_self(void);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy