Index: src/backend/port/win32/signal.c
===================================================================
RCS file: /projects/cvsroot/pgsql/src/backend/port/win32/signal.c,v
retrieving revision 1.14.2.1
diff -c -r1.14.2.1 signal.c
*** src/backend/port/win32/signal.c	22 Nov 2005 18:23:15 -0000	1.14.2.1
--- src/backend/port/win32/signal.c	12 Mar 2006 11:50:11 -0000
***************
*** 28,37 ****
  HANDLE		pgwin32_initial_signal_pipe = INVALID_HANDLE_VALUE;
  
  /*
!  * pg_signal_crit_sec is used to protect only pg_signal_queue. That is the only
   * variable that can be accessed from the signal sending threads!
   */
! static CRITICAL_SECTION pg_signal_crit_sec;
  
  static pqsigfunc pg_signal_array[PG_SIGNAL_COUNT];
  static pqsigfunc pg_signal_defaults[PG_SIGNAL_COUNT];
--- 28,37 ----
  HANDLE		pgwin32_initial_signal_pipe = INVALID_HANDLE_VALUE;
  
  /*
!  * pg_signal_mutex is used to protect only pg_signal_queue. That is the only
   * variable that can be accessed from the signal sending threads!
   */
! static HANDLE pg_signal_mutex;
  
  static pqsigfunc pg_signal_array[PG_SIGNAL_COUNT];
  static pqsigfunc pg_signal_defaults[PG_SIGNAL_COUNT];
***************
*** 61,67 ****
  	int			i;
  	HANDLE		signal_thread_handle;
  
! 	InitializeCriticalSection(&pg_signal_crit_sec);
  
  	for (i = 0; i < PG_SIGNAL_COUNT; i++)
  	{
--- 61,70 ----
  	int			i;
  	HANDLE		signal_thread_handle;
  
! 	pg_signal_mutex = CreateMutex(NULL, FALSE, NULL);
! 	if (pg_signal_mutex == NULL)
! 		ereport(FATAL,
! 				(errmsg_internal("failed to create signal mutex: %d", (int) GetLastError())));
  
  	for (i = 0; i < PG_SIGNAL_COUNT; i++)
  	{
***************
*** 99,105 ****
  {
  	int			i;
  
! 	EnterCriticalSection(&pg_signal_crit_sec);
  	while (UNBLOCKED_SIGNAL_QUEUE())
  	{
  		/* One or more unblocked signals queued for execution */
--- 102,111 ----
  {
  	int			i;
  
! 	if (WaitForSingleObject(pg_signal_mutex, INFINITE) != WAIT_OBJECT_0)
! 		ereport(FATAL,
! 				(errmsg_internal("failed to wait for signal mutex: %d", (int) GetLastError())));
! 
  	while (UNBLOCKED_SIGNAL_QUEUE())
  	{
  		/* One or more unblocked signals queued for execution */
***************
*** 117,125 ****
  				pg_signal_queue &= ~sigmask(i);
  				if (sig != SIG_ERR && sig != SIG_IGN && sig != SIG_DFL)
  				{
! 					LeaveCriticalSection(&pg_signal_crit_sec);
  					sig(i);
! 					EnterCriticalSection(&pg_signal_crit_sec);
  					break;		/* Restart outer loop, in case signal mask or
  								 * queue has been modified inside signal
  								 * handler */
--- 123,137 ----
  				pg_signal_queue &= ~sigmask(i);
  				if (sig != SIG_ERR && sig != SIG_IGN && sig != SIG_DFL)
  				{
! 					if (!ReleaseMutex(pg_signal_mutex))
! 						ereport(FATAL,
! 								(errmsg_internal("failed to release signal mutex: %d", (int) GetLastError())));
! 
  					sig(i);
! 
! 					if (WaitForSingleObject(pg_signal_mutex, INFINITE) != WAIT_OBJECT_0)
! 						ereport(FATAL,
! 								(errmsg_internal("failed to wait for signal mutex: %d", (int) GetLastError())));
  					break;		/* Restart outer loop, in case signal mask or
  								 * queue has been modified inside signal
  								 * handler */
***************
*** 128,134 ****
  		}
  	}
  	ResetEvent(pgwin32_signal_event);
! 	LeaveCriticalSection(&pg_signal_crit_sec);
  }
  
  /* signal masking. Only called on main thread, no sync required */
--- 140,148 ----
  		}
  	}
  	ResetEvent(pgwin32_signal_event);
! 	if (!ReleaseMutex(pg_signal_mutex))
! 		ereport(FATAL,
! 				(errmsg_internal("failed to release signal mutex: %d", (int) GetLastError())));
  }
  
  /* signal masking. Only called on main thread, no sync required */
***************
*** 199,207 ****
  	if (signum >= PG_SIGNAL_COUNT || signum <= 0)
  		return;
  
! 	EnterCriticalSection(&pg_signal_crit_sec);
  	pg_signal_queue |= sigmask(signum);
! 	LeaveCriticalSection(&pg_signal_crit_sec);
  
  	SetEvent(pgwin32_signal_event);
  }
--- 213,225 ----
  	if (signum >= PG_SIGNAL_COUNT || signum <= 0)
  		return;
  
! 	if (WaitForSingleObject(pg_signal_mutex, INFINITE) != WAIT_OBJECT_0)
! 		write_stderr("failed to wait for signal mutex: %d", (int) GetLastError());
! 
  	pg_signal_queue |= sigmask(signum);
! 
! 	if (!ReleaseMutex(pg_signal_mutex))
! 		write_stderr("failed to release signal mutex: %d", (int) GetLastError());
  
  	SetEvent(pgwin32_signal_event);
  }
