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

Commit206378e

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 underlyingcode was changed to deal with return values.
1 parent763c486 commit206378e

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
return1;
41+
InitializeCriticalSection(*mp);
4142
return0;
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
return1;
50+
EnterCriticalSection(*mp);
4951
return0;
5052
}
5153

5254
int
5355
pthread_mutex_unlock(pthread_mutex_t*mp)
5456
{
55-
if (!ReleaseMutex(*mp))
57+
if (!*mp)
5658
return1;
59+
LeaveCriticalSection(*mp);
5760
return0;
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
typedefULONGpthread_key_t;
8-
typedefHANDLEpthread_mutex_t;
8+
typedefCRITICAL_SECTION*pthread_mutex_t;
99
typedefintpthread_once_t;
1010

1111
DWORDpthread_self(void);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp