Article View: comp.sys.amiga.tech
Article #11398Re: Ultimate Wait-GetMsg strategy (?)
From: Tomas G. Rokicki
Date: Fri, 10 Feb 1989 08:43
Date: Fri, 10 Feb 1989 08:43
78 lines
2799 bytes
2799 bytes
>:Now I think I got it:
>:while (1) {
>: while (!(imsg= GetMsg(win->UserPort)))
>: Wait (1<<win->UserPort->mp_SigBit);
>: select imsg->Class and break when ended
>:}
This is *perfectly* fine. while(1)/break is a general looping
construct. while(notquit) is fine, too.
> Yes, that's probably the worse way to do it. Well, not the worse,
>but it's not the best coding style I've seen (you asked for comments!).
First, it's worst, not worse. (What I hear about Berkeley producing
only bit pushers may be true.) Secondly, his code *works*, and the
coding style is one I happen to agree with. Matter of taste, Matt.
> while (notquit) {
> Wait(1 << win->UserPort->mp_SigBit);
> while (mess = GetMsg(win->UserPort)) {
> /* process message */
> ReplyMsg(mess);
> }
> }
Equivalent, *except* that you have a wait at the top that's not guarded
by a `while (GetMsg())' loop. Fine, perhaps, depending on how you enter
the loop and what operations you allow inside the loop (what those
subroutines might do to the signals, you know) but conservative programming
techniques never hurt anyone.
> while (notquit) {
> mask = Wait(mask1 | mask2 | mask3);
>
> if (mask & mask1) { /* say this is for your intuition window */
> register struct IntuiMessage *mess;
> while (mess = GetMsg(win->UserPort)) {
> /* process all messages */
> ReplyMsg(mess);
> }
> }
> if (mask & mask2) {
> /* etc... */
> }
> if (mask & mask3) {
> /* etc... */
> }
> }
Not very fair; mask1 can dominate, causing problems later. Something
like
int msgseen ;
while (notquit) {
msgseen = 0 ;
if (msg = GetMsg(port1)) {
msgseen = 1 ;
}
if (msg = GetMsg(port2)) {
msgseen = 1 ;
}
if (msg = GetMsg(port2)) {
msgseen = 1 ;
}
if (! msgseen)
Wait(mask1 | mask2 | mask3) ;
}
might work a little better. Remember, GetMsg() is *very* quick if no
messages are on the port. And your mousemove's won't completely lock
out your serial I/O. (You can change any one of the above `if (msg...'
to while's, for things that *need* processing with a fair minimal
latency.)
> -Matt
Sorry for the flaming tone of this article, Matt. I just hate people
cutting down other people's coding style like that.
Technical Details
Message-ID:
<6777@polya.Stanford.EDU>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!purdue!decwrl!labrea!polya!rokickiReferences:
<8902100658.AA16049@postgres.Berkeley.EDU>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!purdue!decwrl!labrea!polya!rokicki From: rokicki@polya.Stanford.EDU (Tomas G. Rokicki) Newsgroups: comp.sys.amiga.tech Subject: Re: Ultimate Wait-GetMsg strategy (?) Message-ID: <6777@polya.Stanford.EDU> Date: 10 Feb 89 08:43:09 GMT References: <8902100658.AA16049@postgres.Berkeley.EDU> Reply-To: rokicki@polya.Stanford.EDU (Tomas G. Rokicki) Organization: Stanford University Lines: 78