From: monster@mbear.apana.org.au (Martin Ozolins)
Newsgroups: comp.sys.amiga.programmer
Subject: Problem with the following Code
Date: 16 Oct 92 06:24:39 GMT
Organization: Bears Incorporated
X-NewsSoftware: GRn 1.16e (7/4/92) by Mike Schwartz & Michael B. Smith


What is supposed to happen is this.

The code waits until either 10 seconds has passed or the user presses one of the 
Gadgets.
If the user presses QUIT we close up shop and leave, else we do what we want and
then wait again.

Everthing works OK until the user presses a Gadget, then what happens is the code
acts as if a timersig signal is received instantaneously thus the code uses up
all the available CPU time until QUIT is pressed.

If I do a wait on just gadsig everything is OK.

I am using SAS/C v5.10.

 while ( ! endit )    /* lets loop */
 {                    
    if ( !( CheckIO(( struct TimerIO *)TimerIO )))
    {
       AbortIO(( struct TimerIO * )TimerIO );
       WaitIO(( struct TimerIO *)TimerIO );
    }
                        
    timersig = ( 1L << timerp->mp_SigBit );
    gadsig   = ( 1L << MSMScrWnd->UserPort->mp_SigBit );
                                           
    TimerIO->tr_node.io_Command = TR_ADDREQUEST;
    TimerIO->tr_time.tv_secs = 10; /* wait 10 seconds */
    TimerIO->tr_time.tv_micro = 0;
    SendIO(( struct IORequest *) TimerIO);

                        
    signal   = Wait( timersig | gadsig ); 
                                                                                                
    if ( signal & gadsig )                        
    {   
       ( imsg = GT_GetIMsg( MSMScrWnd->UserPort ));                        
       g = (struct Gadget *)imsg->IAddress;
        
       imsgClass = imsg->Class;
       imsgCode  = imsg->Code;
           
       GT_ReplyIMsg( imsg );
            
       switch ( imsgClass )
       {                                    
          case  IDCMP_GADGETDOWN: 
          case  IDCMP_GADGETUP:
          {
             switch ( g->GadgetID)
             {
                case  GD_Quit:
                   endit = TRUE;
                   /* Ensure that the timer.devvice has NO 
                      outstanding I/Os before we close up 
                      shop and leave */
                   if( !( CheckIO(( struct TimerIO *)TimerIO )))
                   {
                      AbortIO(( struct TimerIO * )TimerIO );
                      WaitIO(( struct TimerIO *)TimerIO );
                   }                                                                                   
                break;
                case  GD_Usage: /* do other code in here */
                   break;
              }
           }               
           break;               
       }
    }
    if ( signal & timersig )                            
    {
       /* Make sure that we get ALL the msgs from the Port */
       while ((struct Message *)GetMsg( timerp ));                            
       setup_status2(); /* update the status display */
    }                           
                   
 }

-- 

Martin Ozolins :Internet   monster@mbear.apana.org.au
Victoria       :FIDO       3:633/359.6
Australia      :AMIGANET   41:300/359.6
               :TRINET     42:8699/8.6