ivan@dbaccess.com (Ivan Covdy) (09/19/90)
I received a lot of mail with the same question:
Why I need to pass parameters to Action() when calling signal( SIGN, Action).
In a simplified form, my problem looks like this.
There is WaitSignal() function which should catch, let us say, SIGN1
and SIGN2, from another process, and, dependent upon the signal's type,
change the contains of the shared buffer (pointer to this buffer,
pSharedMem, is passed to WaitSignal):
WaitSignal( char *pSharedMem )
{
...
signal( SIGN1, Action );
signal( SIGN2, Action );
...
}
void Action( int Signal )
{
...
switch ( Signal )
{
case SIGN1: *pSharedMem = 'A'; break;
case SIGN2: *pSharedMem = 'B'; break;
...
}
...
}
My limitation is that I cannot have external/global variables for
functions Action() and WaitSignal(), because these functions can be
linked to several mains() by different ways on different systems
(...well, common code can be called from multiple tasks).
Hence, there is a problem to access pSharedMem inside of Action()
and/or Signal inside of WaitSignal().
Thank you for your help.
--
Ivan Covdy INTERNET: ivan@dbaccess.com
c/o DB/Access Inc. UUCP: {uunet,mips}!troi!ivan
2900 Gordon Avenue, Suite 101 FAX: (408) 735-0328
Santa Clara, CA 95051 TEL: (408) 735-7545les@chinet.chi.il.us (Leslie Mikesell) (09/19/90)
In article <122@wookie.dbaccess.com> ivan@dbaccess.com (Ivan Covdy) writes: >My limitation is that I cannot have external/global variables for >functions Action() and WaitSignal(), because these functions can be >linked to several mains() by different ways on different systems >(...well, common code can be called from multiple tasks). As long as you don't allow recursion (and if WaitSignal() actually waits you obviously don't), all you have to do is declare a static variable outside of the functions to hold your pointer and copy the parameter passed to WaitSignal() there. As long as the Action() function resides in the same source file, it will be able to access the static variable, but the name will not be visible elsewhere. You may have other problems with this code, though, like signals arriving before you are ready unless WaitSignal() also notifies the other process(es) when it is prepared to receive them. Les Mikesell les@chinet.chi.il.us