Re: libpq Win32 Mutex performance patch - Mailing list pgsql-patches

From Andrew Chernow
Subject Re: libpq Win32 Mutex performance patch
Date
Msg-id 47FFBAED.7030100@esilo.com
Whole thread Raw
In response to Re: libpq Win32 Mutex performance patch  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: libpq Win32 Mutex performance patch  (Andrew Chernow <ac@esilo.com>)
Re: libpq Win32 Mutex performance patch  (Magnus Hagander <magnus@hagander.net>)
Re: libpq Win32 Mutex performance patch  (Alvaro Herrera <alvherre@commandprompt.com>)
List pgsql-patches
Tom Lane wrote:
>Silently not locking is surely
> not very safe.
>

Here is the dump code version of the patch.  If anyone wants the return
value idea, let me know.

--
Andrew Chernow
eSilo, LLC
every bit counts
http://www.esilo.com/
Index: src/port/pthread-win32.h
===================================================================
RCS file: /projects/cvsroot/pgsql/src/port/pthread-win32.h,v
retrieving revision 1.2
diff -c -r1.2 pthread-win32.h
*** src/port/pthread-win32.h    18 Apr 2007 08:32:40 -0000    1.2
--- src/port/pthread-win32.h    11 Apr 2008 19:22:17 -0000
***************
*** 2,8 ****
  #define __PTHREAD_H

  typedef ULONG pthread_key_t;
! typedef HANDLE pthread_mutex_t;
  typedef int pthread_once_t;

  DWORD        pthread_self(void);
--- 2,8 ----
  #define __PTHREAD_H

  typedef ULONG pthread_key_t;
! typedef CRITICAL_SECTION *pthread_mutex_t;
  typedef int pthread_once_t;

  DWORD        pthread_self(void);
Index: src/interfaces/libpq/pthread-win32.c
===================================================================
RCS file: /projects/cvsroot/pgsql/src/interfaces/libpq/pthread-win32.c,v
retrieving revision 1.15
diff -c -r1.15 pthread-win32.c
*** src/interfaces/libpq/pthread-win32.c    1 Jan 2008 19:46:00 -0000    1.15
--- src/interfaces/libpq/pthread-win32.c    11 Apr 2008 19:22:17 -0000
***************
*** 35,51 ****
  void
  pthread_mutex_init(pthread_mutex_t *mp, void *attr)
  {
!     *mp = CreateMutex(0, 0, 0);
  }

  void
  pthread_mutex_lock(pthread_mutex_t *mp)
  {
!     WaitForSingleObject(*mp, INFINITE);
  }

  void
  pthread_mutex_unlock(pthread_mutex_t *mp)
  {
!     ReleaseMutex(*mp);
  }
--- 35,61 ----
  void
  pthread_mutex_init(pthread_mutex_t *mp, void *attr)
  {
!     *mp = (CRITICAL_SECTION *)malloc(sizeof(CRITICAL_SECTION));
!     InitializeCriticalSection(*mp);
  }

  void
  pthread_mutex_lock(pthread_mutex_t *mp)
  {
!     EnterCriticalSection(*mp);
  }

  void
  pthread_mutex_unlock(pthread_mutex_t *mp)
  {
!     LeaveCriticalSection(*mp);
  }
+
+ /* If ever needed
+ void pthread_mutex_destroy(pthread_mutex_t *mp)
+ {
+     DeleteCriticalSection(*mp);
+     free(*mp);
+     *mp = NULL;
+ }
+ */
\ No newline at end of file

pgsql-patches by date:

Previous
From: Andrew Chernow
Date:
Subject: Re: libpq Win32 Mutex performance patch
Next
From: Bruce Momjian
Date:
Subject: Re: Maintaining cluster order on insert