home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.sys.amiga.programmer
- Path: sparky!uunet!gatech!concert!samba!usenet
- From: Todd_Lewis@unc.edu (Todd M. Lewis)
- Subject: Re: RKM description of WaitPort()
- Message-ID: <1993Jan7.201052.13703@samba.oit.unc.edu>
- Sender: usenet@samba.oit.unc.edu
- Nntp-Posting-Host: guitar.oit.unc.edu
- Organization: UNC Office of Information Technology
- References: <38385@cbmvax.commodore.com>
- Date: Thu, 7 Jan 1993 20:10:52 GMT
- Lines: 74
-
- In article <38385@cbmvax.commodore.com> peter@cbmvax.commodore.com (Peter
- Cherna) writes:
- >[...]Try this to handle messages from two ports:
- >
- > struct MsgPort *mp1 = your first message port;
- > struct MsgPort *mp2 = your second message port;
- >
- > sigmask1 = 1 << mp1->mp_SigBit;
- > sigmask2 = 1 << mp2->mp_SigBit;
- >
- > while ( !done )
- > {
- > sigmask = Wait( sigmask1 | sigmask2 );
- > if ( sigmask & sigmask1 )
- > {
- > while ( msg1 = GetMsg( mp1 ) )
- > {
- > handle messages from port 1 ...
- > }
- > }
- > if ( sigmask & sigmask2 )
- > {
- > while ( msg2 = GetMsg( mp2 ) )
- > {
- > handle messages from port 2 ...
- > }
- > }
- > }
-
- I've used this dozens of times, but the other day I was getting
- messages from port 1 faster than I could process them so that
- I never got around to processing port 2's message, an act which
- would have made port 1's messages stop comming. A busy dead-lock.
- Now I do something like this:
-
- while ( !done )
- {
- sigmask = Wait( sigmask1 | sigmask2 );
- while ( (msg1 = GetMsg( mp1 )), (msg2 = GetMsg( mp2 )), (msg1 || msg2) )
- {
- if ( msg1 )
- {
- handle a message from port 1 ...
- }
- if ( msg2 )
- {
- handle a message from port 2 ...
- }
- }
- }
-
- This way both ports get roughly equal treatment, whereas in the example
- Peter gave port 1's messages must all be handled before port 2 even
- gets looked at.
-
- Note that "while ( (msg1 = GetMsg( mp1 )) || (msg2 = GetMsg( mp2 )) )"
- wouldn't solve the problem because the second GetMsg() would not
- be called if the first GetMsg() actually got a message.
-
- Some people might like this better:
- do {
- if (msg1 = GetMsg( mp1 ))
- {
- handle a message from port 1...
- }
- if (msg2 = GetMsg( mp2 ))
- {
- handle a message from port 2...
- }
- } while ( msg1 || msg2 );
- --
- _/_/_/ _/ Todd_Lewis@unc.edu You can lead a horse to
- _/ _/ utoddl@guitar.oit.unc.edu Mohammad, but you can't make
- _/ _/_/_/ a mountain drink a mole hill.
-