Hi,

Daniel Horak wrote:

> Hi,
> 
> please add the file ipc.patch (patch for the cygipc library) into src/win32
> directory and apply the patch for README.NT (readme.patch). I think it
> should go into both the 6.5.2 and current trees.
> 
> I have no reaction from the author of the cygipc library yet, so it will be
> better to include the patch into the sources of PostgreSQL

I propose more patch against cygipc. 

Hiroshi Inoue (inoue@tpf.co.jp) found another backend freezing problem.
He also found semop() in cygipc can't decrement semaphore value
correctly (Only -1 is supported).

I create follwing patch fixes these issues.


I'm sorry for my poor English.

*** sem.c.orig_	Tue Aug 17 14:19:37 1999
--- sem.c	Tue Aug 31 16:59:49 1999
***************
*** 204,210 ****
      {
  	CloseHandle ( LHandle ) ;
      }
!     LHandle = CreateSemaphore(NULL, 0, 0x7FFFFFFF, LBuff) ;
      if( LHandle == NULL )
      {
  	printf( "Creation de Semaphore \"Sem\" impossible\n" ) ;
--- 204,210 ----
      {
  	CloseHandle ( LHandle ) ;
      }
!     LHandle = CreateSemaphore(NULL, 0, 1, LBuff) ;
      if( LHandle == NULL )
      {
  	printf( "Creation de Semaphore \"Sem\" impossible\n" ) ;
***************
*** 374,388 ****
  debug_printf("do_semop : return -EACCES\n");
  			CYGWIN32_IPCNT_RETURN (-EACCES) ;
  		    }
! 		    ReleaseSemaphore(LHandle, sop->sem_op, &LVal) ;
! 	    	    shareadrsem->current_nb[id].current_nb[sop->sem_num] +=
! 					sop->sem_op ;
  		    sem_deconnect() ;
  		} else {
  		    if( sop->sem_flg == IPC_NOWAIT )
  		    {
! 			LRet = WaitForSingleObject(LHandle, 0) ;
! 			if( LRet == WAIT_TIMEOUT )
  			{
  debug_printf("do_semop : return -EAGAIN\n");
  			    CYGWIN32_IPCNT_RETURN (-EAGAIN) ;
--- 374,387 ----
  debug_printf("do_semop : return -EACCES\n");
  			CYGWIN32_IPCNT_RETURN (-EACCES) ;
  		    }
!     	    shareadrsem->current_nb[id].current_nb[sop->sem_num] +=
! 				sop->sem_op ;
  		    sem_deconnect() ;
+ 		    ReleaseSemaphore(LHandle, 1 , &LVal) ;
  		} else {
  		    if( sop->sem_flg == IPC_NOWAIT )
  		    {
! 			if( sop->sem_op + shareadrsem->current_nb[id].current_nb[sop->sem_num] <0 )
  			{
  debug_printf("do_semop : return -EAGAIN\n");
  			    CYGWIN32_IPCNT_RETURN (-EAGAIN) ;
***************
*** 392,407 ****
  debug_printf("do_semop : return -EACCES\n");
  			    CYGWIN32_IPCNT_RETURN (-EACCES) ;
  			}
! 	    		shareadrsem->current_nb[id].current_nb[sop->sem_num] -= 1 ;
  			sem_deconnect() ;
  		    } else {
! 			LRet = WaitForSingleObject(LHandle, INFINITE) ;
  			if (sem_connect() == 0)
  			{
  debug_printf("do_semop : return -EACCES\n");
  			    CYGWIN32_IPCNT_RETURN (-EACCES) ;
  			}
! 			    shareadrsem->current_nb[id].current_nb[sop->sem_num] -= 1 ;
  			    sem_deconnect() ;
  		    }
  		}
--- 391,408 ----
  debug_printf("do_semop : return -EACCES\n");
  			    CYGWIN32_IPCNT_RETURN (-EACCES) ;
  			}
! 	    		shareadrsem->current_nb[id].current_nb[sop->sem_num] += sop->sem_op;
  			sem_deconnect() ;
  		    } else {
! 		    while(sop->sem_op + shareadrsem->current_nb[id].current_nb[sop->sem_num] <0)
! 				LRet = WaitForSingleObject(LHandle, INFINITE) ;
! 		    
  			if (sem_connect() == 0)
  			{
  debug_printf("do_semop : return -EACCES\n");
  			    CYGWIN32_IPCNT_RETURN (-EACCES) ;
  			}
! 			    shareadrsem->current_nb[id].current_nb[sop->sem_num] += sop->sem_op ;
  			    sem_deconnect() ;
  		    }
  		}
***************
*** 452,458 ****
  	char LBuff[100] ;
  	HANDLE LHandle ;
  	long LPrevious ;
- 	int LIndex;
  
  debug_printf("semctl : semid=%X semnum=%X cmd=0x%02X arg=%p\n",semid,semnum,cmd,arg);
  	if (semid < 0 || semnum < 0 || cmd < 0)
--- 453,458 ----
***************
*** 585,606 ****
  		if( LHandle != NULL )
  		{
  		    if( arg.val > shareadrsem->current_nb[id].current_nb[semnum] )
! 		    {
! 			ReleaseSemaphore(LHandle,
! 			arg.val-shareadrsem->current_nb[id].current_nb[semnum],
! 			&LPrevious) ;
! 		    }
! 		    else if (arg.val <
! 		             shareadrsem->current_nb[id].current_nb[semnum] )
! 		    {
! 			for( LIndex = arg.val;
! 			LIndex < shareadrsem->current_nb[id].current_nb[semnum];
! 			LIndex++ )
! 			{
! 			    WaitForSingleObject(LHandle, 0) ;
! 			}
! 		    }
!             	    shareadrsem->current_nb[id].current_nb[semnum] = arg.val ;
  		}
  debug_printf("semctl : SETVAL : return 0\n");
  		CYGWIN32_IPCNT_RETURN_DECONNECT (0);
--- 585,592 ----
  		if( LHandle != NULL )
  		{
  		    if( arg.val > shareadrsem->current_nb[id].current_nb[semnum] )
! 				ReleaseSemaphore(LHandle,1,&LPrevious) ;
!             shareadrsem->current_nb[id].current_nb[semnum] = arg.val ;
  		}
  debug_printf("semctl : SETVAL : return 0\n");
  		CYGWIN32_IPCNT_RETURN_DECONNECT (0);



--
Yutaka tanida / S34 Co., Ltd.
tanida@s34.co.jp (Office)
yutaka@marin.or.jp(Private, or if you *HATE* Microsoft Outlook)


Tue, 31 Aug 1999 17:38:59 +0900
yutaka tanida <yutaka@marin.or.jp>
Re: IPC on win32 - additions for 6.5.2 and current trees
NT folks, I assume this patch is no longer needed.


> Hi,
> 
> Daniel Horak wrote:
> 
> > Hi,
> > 
> > please add the file ipc.patch (patch for the cygipc library) into src/win32
> > directory and apply the patch for README.NT (readme.patch). I think it
> > should go into both the 6.5.2 and current trees.
> > 
> > I have no reaction from the author of the cygipc library yet, so it will be
> > better to include the patch into the sources of PostgreSQL
> 
> I propose more patch against cygipc. 
> 
> Hiroshi Inoue (inoue@tpf.co.jp) found another backend freezing problem.
> He also found semop() in cygipc can't decrement semaphore value
> correctly (Only -1 is supported).
> 
> I create follwing patch fixes these issues.
> 
> 
> I'm sorry for my poor English.
> 
> *** sem.c.orig_	Tue Aug 17 14:19:37 1999
> --- sem.c	Tue Aug 31 16:59:49 1999
> ***************
> *** 204,210 ****
>       {
>   	CloseHandle ( LHandle ) ;
>       }
> !     LHandle = CreateSemaphore(NULL, 0, 0x7FFFFFFF, LBuff) ;
>       if( LHandle == NULL )
>       {
>   	printf( "Creation de Semaphore \"Sem\" impossible\n" ) ;
> --- 204,210 ----
>       {
>   	CloseHandle ( LHandle ) ;
>       }
> !     LHandle = CreateSemaphore(NULL, 0, 1, LBuff) ;
>       if( LHandle == NULL )
>       {
>   	printf( "Creation de Semaphore \"Sem\" impossible\n" ) ;
> ***************
> *** 374,388 ****
>   debug_printf("do_semop : return -EACCES\n");
>   			CYGWIN32_IPCNT_RETURN (-EACCES) ;
>   		    }
> ! 		    ReleaseSemaphore(LHandle, sop->sem_op, &LVal) ;
> ! 	    	    shareadrsem->current_nb[id].current_nb[sop->sem_num] +=
> ! 					sop->sem_op ;
>   		    sem_deconnect() ;
>   		} else {
>   		    if( sop->sem_flg == IPC_NOWAIT )
>   		    {
> ! 			LRet = WaitForSingleObject(LHandle, 0) ;
> ! 			if( LRet == WAIT_TIMEOUT )
>   			{
>   debug_printf("do_semop : return -EAGAIN\n");
>   			    CYGWIN32_IPCNT_RETURN (-EAGAIN) ;
> --- 374,387 ----
>   debug_printf("do_semop : return -EACCES\n");
>   			CYGWIN32_IPCNT_RETURN (-EACCES) ;
>   		    }
> !     	    shareadrsem->current_nb[id].current_nb[sop->sem_num] +=
> ! 				sop->sem_op ;
>   		    sem_deconnect() ;
> + 		    ReleaseSemaphore(LHandle, 1 , &LVal) ;
>   		} else {
>   		    if( sop->sem_flg == IPC_NOWAIT )
>   		    {
> ! 			if( sop->sem_op + shareadrsem->current_nb[id].current_nb[sop->sem_num] <0 )
>   			{
>   debug_printf("do_semop : return -EAGAIN\n");
>   			    CYGWIN32_IPCNT_RETURN (-EAGAIN) ;
> ***************
> *** 392,407 ****
>   debug_printf("do_semop : return -EACCES\n");
>   			    CYGWIN32_IPCNT_RETURN (-EACCES) ;
>   			}
> ! 	    		shareadrsem->current_nb[id].current_nb[sop->sem_num] -= 1 ;
>   			sem_deconnect() ;
>   		    } else {
> ! 			LRet = WaitForSingleObject(LHandle, INFINITE) ;
>   			if (sem_connect() == 0)
>   			{
>   debug_printf("do_semop : return -EACCES\n");
>   			    CYGWIN32_IPCNT_RETURN (-EACCES) ;
>   			}
> ! 			    shareadrsem->current_nb[id].current_nb[sop->sem_num] -= 1 ;
>   			    sem_deconnect() ;
>   		    }
>   		}
> --- 391,408 ----
>   debug_printf("do_semop : return -EACCES\n");
>   			    CYGWIN32_IPCNT_RETURN (-EACCES) ;
>   			}
> ! 	    		shareadrsem->current_nb[id].current_nb[sop->sem_num] += sop->sem_op;
>   			sem_deconnect() ;
>   		    } else {
> ! 		    while(sop->sem_op + shareadrsem->current_nb[id].current_nb[sop->sem_num] <0)
> ! 				LRet = WaitForSingleObject(LHandle, INFINITE) ;
> ! 		    
>   			if (sem_connect() == 0)
>   			{
>   debug_printf("do_semop : return -EACCES\n");
>   			    CYGWIN32_IPCNT_RETURN (-EACCES) ;
>   			}
> ! 			    shareadrsem->current_nb[id].current_nb[sop->sem_num] += sop->sem_op ;
>   			    sem_deconnect() ;
>   		    }
>   		}
> ***************
> *** 452,458 ****
>   	char LBuff[100] ;
>   	HANDLE LHandle ;
>   	long LPrevious ;
> - 	int LIndex;
>   
>   debug_printf("semctl : semid=%X semnum=%X cmd=0x%02X arg=%p\n",semid,semnum,cmd,arg);
>   	if (semid < 0 || semnum < 0 || cmd < 0)
> --- 453,458 ----
> ***************
> *** 585,606 ****
>   		if( LHandle != NULL )
>   		{
>   		    if( arg.val > shareadrsem->current_nb[id].current_nb[semnum] )
> ! 		    {
> ! 			ReleaseSemaphore(LHandle,
> ! 			arg.val-shareadrsem->current_nb[id].current_nb[semnum],
> ! 			&LPrevious) ;
> ! 		    }
> ! 		    else if (arg.val <
> ! 		             shareadrsem->current_nb[id].current_nb[semnum] )
> ! 		    {
> ! 			for( LIndex = arg.val;
> ! 			LIndex < shareadrsem->current_nb[id].current_nb[semnum];
> ! 			LIndex++ )
> ! 			{
> ! 			    WaitForSingleObject(LHandle, 0) ;
> ! 			}
> ! 		    }
> !             	    shareadrsem->current_nb[id].current_nb[semnum] = arg.val ;
>   		}
>   debug_printf("semctl : SETVAL : return 0\n");
>   		CYGWIN32_IPCNT_RETURN_DECONNECT (0);
> --- 585,592 ----
>   		if( LHandle != NULL )
>   		{
>   		    if( arg.val > shareadrsem->current_nb[id].current_nb[semnum] )
> ! 				ReleaseSemaphore(LHandle,1,&LPrevious) ;
> !             shareadrsem->current_nb[id].current_nb[semnum] = arg.val ;
>   		}
>   debug_printf("semctl : SETVAL : return 0\n");
>   		CYGWIN32_IPCNT_RETURN_DECONNECT (0);
> 
> 
> 
> --
> Yutaka tanida / S34 Co., Ltd.
> tanida@s34.co.jp (Office)
> yutaka@marin.or.jp(Private, or if you *HATE* Microsoft Outlook)
> 
> 
> ************
> 
> 


-- 
  Bruce Momjian                        |  http://www.op.net/~candle
  maillist@candle.pha.pa.us            |  (610) 853-3000
  +  If your life is a hard drive,     |  830 Blythe Avenue
  +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026

Mon, 27 Sep 1999 16:49:08 -0400 (EDT)
Bruce Momjian <maillist@candle.pha.pa.us>
Re: [HACKERS] Re: IPC on win32 - additions for 6.5.2 and current
 trees
> -----Original Message-----
> From: Bruce Momjian [mailto:maillist@candle.pha.pa.us]
> Sent: Tuesday, September 28, 1999 5:49 AM
> To: yutaka tanida
> Cc: pgsql-hackers@hub.org; inoue@tpf.co.jp
> Subject: Re: [HACKERS] Re: IPC on win32 - additions for 6.5.2 and
> current trees
> 
> 
> NT folks, I assume this patch is no longer needed.
>

No,his patch is needed.
I have already committed a new patch which combines Yutaka's and
my patch to current tree under src/win32.

Regards.

Hiroshi Inoue
Inoue@tpf.co.jp

Tue, 28 Sep 1999 08:53:31 +0900
"Hiroshi Inoue" <Inoue@tpf.co.jp>
RE: [HACKERS] Re: IPC on win32 - additions for 6.5.2 and current
 trees
[Charset iso-8859-1 unsupported, filtering to ASCII...]
> > -----Original Message-----
> > From: Bruce Momjian [mailto:maillist@candle.pha.pa.us]
> > Sent: Tuesday, September 28, 1999 5:49 AM
> > To: yutaka tanida
> > Cc: pgsql-hackers@hub.org; inoue@tpf.co.jp
> > Subject: Re: [HACKERS] Re: IPC on win32 - additions for 6.5.2 and
> > current trees
> > 
> > 
> > NT folks, I assume this patch is no longer needed.
> >
> 
> No,his patch is needed.
> I have already committed a new patch which combines Yutaka's and
> my patch to current tree under src/win32.

OK, patch removed from README, and user pointed to new file in win32
directory.

-- 
  Bruce Momjian                        |  http://www.op.net/~candle
  maillist@candle.pha.pa.us            |  (610) 853-3000
  +  If your life is a hard drive,     |  830 Blythe Avenue
  +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026

Mon, 27 Sep 1999 21:42:17 -0400 (EDT)
Bruce Momjian <maillist@candle.pha.pa.us>
Re: [HACKERS] Re: IPC on win32 - additions for 6.5.2 and current
 trees