🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.sys.amiga.tech
Article #2660

CloseWindowSafely

#2660
From: Usenet file owner
Date: Mon, 11 Dec 1989 01:54
74 lines
3226 bytes
: 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*/
	    }
	    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.

It should also be in release 1.4 somewhere.

I can't wait for 1.4.
 Joe Porkka   porkka@frith.egr.msu.edu
Technical Details
Message-ID: <5740@cps3xx.UUCP>
Path: arc1-ca.pugleaf.net!utzoo!attcan!utgpu!jarvis.csri.toronto.edu!clyde.concordia.ca!uunet!tut.cis.ohio-state.edu!mailrus!ames!ncar!tank!cps3xx!usenet

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!utgpu!jarvis.csri.toronto.edu!clyde.concordia.ca!uunet!tut.cis.ohio-state.edu!mailrus!ames!ncar!tank!cps3xx!usenet
From: usenet@cps3xx.UUCP (Usenet file owner)
Newsgroups: comp.sys.amiga.tech
Subject: CloseWindowSafely
Message-ID: <5740@cps3xx.UUCP>
Date: 11 Dec 89 01:54:53 GMT
Reply-To: porkka@frith.egr.msu.edu ()
Organization: Michigan State University
Lines: 74