Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!clyde.concordia.ca!rutgers!cbmvax!mks From: mks@cbmvax.commodore.com (Michael Sinz - CATS) Newsgroups: comp.sys.amiga.tech Subject: Re: CloseWindowSafely Message-ID: <8976@cbmvax.commodore.com> Date: 13 Dec 89 14:32:56 GMT References: <5740@cps3xx.UUCP> Reply-To: mks@cbmvax.commodore.com (Michael Sinz - CATS) Organization: Commodore, West Chester, PA Lines: 99 In article <5740@cps3xx.UUCP> porkka@frith.egr.msu.edu () writes: > >: From: ames!dtg.nsc.com!waggoner (Mark Waggoner) >: To: porkka@frith.egr.msu.edu >: Subject: CloseWindowSafely() >: >: Hello, >: I've been following, and slightly involved in, the recent discussions >: about sharing a message port among several windows. I've used this method >: before and, when closing a window, I merely made sure there were no messages >: waiting at the msgport and did a normal CloseWindow(). I have seen >This is basically exactly what CloseWindowSafely does. >: you and others mention CloseWindowSafely a number of times but I can find no >: mention of such a routine in the many manuals I have. The closest they >: come to it is a strong warning to make sure you have no messages pending from >: the window when it is closed. >: >: Can you give me the details of CloseWindowSafely() or send the code for it? >: I want to be sure I am doing everything I can to prevent system crashes. >: >: Thanks, >: Mark Waggoner >: waggoner@dtg.nsc.com >: > >Here is a rough sketch of CloseWindowSafely > CloseWindowSafely(win) > struct Window *win; > { > struct MsgPort myport = win->UserPort; > struct Node *x, *y; > struct IntuiMsg *t; > > SetIDCMP(win, 0L); /* Inhibit any further msgs for this window*/ > win->UserPort=0; /* Prevent intuition from freeing my port */ > > Forbid(); /* Prevent the Msg system from posting > messages to "myport" while I fiddle with it */ > for(x=myport->head; x!=endoflist;x=y) { > y=x->next; > t=x; > if(t->window == win) Reply(x); /* Send it back*/ > } You forgot to remove the message from the message port. This could cause (actually it WILL cause) a GURU. Using the loop you have there, the line with the if(t->window...) should be replaced by: if(t->window==win) { Remove(t); Reply(t); } > Permit(); > CloseWindow(win); > } > >Why all of this? >Intuition keeps a list of all the msgs bodies that it has used >for a particular window. When the window is closed, it simply FreeMems() >them. If they are still part of a list (say, attached to a MsgPort) >then that list will become currupted, and call Mr. GURU. > >So three thing need to be done before closing the window. First, stop >intuition from sending any new msgs to the msgport from this window. >Second clear the UserPort field of the Window so that intuition >won't free the port for you, since you are still using it. >Third, reply to msgs for this window that are already at the port, >thusly removing them from the ports msg list. > >Then the window can be closed. The msgs that were used for this >window will then be freed, which is OK since they are not part of >you MsgPort msg list. > >For a working example see my "windows.c" code in my "hyperhelp" program. >This example also deals with fonts. THis is archived at "uunet.uu.net" >in the "pub/comp.sources.amiga" directory", or I could email it to >you. > >The orignal "closeWindowSafely" is on a fishdisk I think. And in an old AmigaMail and in the new RKM Libraries & Devices volume. > >It should also be in release 1.4 somewhere. > >I can't wait for 1.4. > Joe Porkka porkka@frith.egr.msu.edu /----------------------------------------------------------------------\ | /// Michael Sinz -- CATS/Amiga Software Engineer | | /// PHONE 215-431-9422 UUCP ( uunet | rutgers ) !cbmvax!mks | | /// | |\\\/// When people are free to do as they please, | | \XX/ they usually imitate each other. | \----------------------------------------------------------------------/