[comp.sys.amiga.tech] Locking & forbiding

dwl10@uts.amdahl.com (Dave Lowrey) (06/07/89)

I am writing a progra that gets the pointer to the current
window from IntuitionBase. It then modifies either the pointer to the
window's title, or the data pointed to by said pointer.

The RKM says to LockIBase() before referencing IntuitionBase. So, that
is no problem. Now, will that also protect me while I mess  with the
Title pointer, or should I Forbid() first?

Thanks in advance......

Dave

-- 
"What is another word  |  Dave Lowrey    | [The opinions expressed MAY be
 for 'Thesaurus'?"     |  Amdahl Corp.   | those of the author and are not
                       |  Houston, Texas | necessarily those of his
   Steven Wright       |  amdahl!dwl10   | employer]   (`nuff said!)

cmcmanis%pepper@Sun.COM (Chuck McManis) (06/07/89)

In article <7cBq029532iy01@amdahl.uts.amdahl.com> (Dave Lowrey) writes:
->I am writing a progra that gets the pointer to the current
->window from IntuitionBase. It then modifies either the pointer to the
->window's title, or the data pointed to by said pointer.

Why don't you use SetWindowTitle()?


--Chuck McManis
uucp: {anywhere}!sun!cmcmanis   BIX: cmcmanis  ARPAnet: cmcmanis@sun.com
These opinions are my own and no one elses, but you knew that didn't you.
"A most excellent barbarian ... Genghis Kahn!"

dwl10@uts.amdahl.com (Dave Lowrey) (06/07/89)

In article <108333@sun.Eng.Sun.COM> cmcmanis@sun.UUCP (Chuck McManis) writes:
>In article <7cBq029532iy01@amdahl.uts.amdahl.com> (Dave Lowrey) writes:
>->I am writing a progra that gets the pointer to the current
>->window from IntuitionBase. It then modifies either the pointer to the
>->window's title, or the data pointed to by said pointer.
>
>Why don't you use SetWindowTitle()?
>
>
>--Chuck McManis

I need to get the address of the current title, as well as
setting a new title.

So I guess I am asking if it is safe to access this info
without any locking.

-- 
"What is another word  |  Dave Lowrey    | [The opinions expressed MAY be
 for 'Thesaurus'?"     |  Amdahl Corp.   | those of the author and are not
                       |  Houston, Texas | necessarily those of his
   Steven Wright       |  amdahl!dwl10   | employer]   (`nuff said!)

cmcmanis%pepper@Sun.COM (Chuck McManis) (06/08/89)

I wrote : 
>Why don't you use SetWindowTitle()?

In article <d2YG02GD32Hm01@amdahl.uts.amdahl.com> (Dave Lowrey) writes:
>I need to get the address of the current title, as well as
>setting a new title.
>
>So I guess I am asking if it is safe to access this info
>without any locking.

Hmmmm, why do I get the feeling that you aren't doing something that 
one my consider "normal" programming practice? :-) 

So to be completely blunt and open about this :

	You opened a window, so you have a pointer to the window. You 
	can use SetWindowTitles() to change it to whatever you want.
	No locking required because you are the only one who will be
	playing with your window title.  Further you could cache 
	Window->Title before you set the title so that you restore 
	the title that you originally had on the window, or of course 
	you could just use the same pointer that you gave in the 
	NewWindow structure. 

	There is of course the "hack" case, which is to say you have
	a pointer to a window that you did not open and do not own.
	In which case you have absolutely no business at all mucking
	with it's title because there is no locking mechanisim in the
	world that can protect you from the application who actually
	owns the window and might do any arbitrarily legal thing, like
	substituting the title and calling FreeMem() on the pointer 
	that was in there. And if you had stuffed in some bogus title
	the Application will have quite legally freed your memory for
	you and you and it both will probably crash.  

By the way, I couldn't find any reference in IntuitionBase that had
to do with titles anyway. Where were you looking?


--Chuck McManis
uucp: {anywhere}!sun!cmcmanis   BIX: cmcmanis  ARPAnet: cmcmanis@sun.com
These opinions are my own and no one elses, but you knew that didn't you.
"A most excellent barbarian ... Genghis Kahn!"

dwl10@uts.amdahl.com (Dave Lowrey) (06/08/89)

In article <108749@sun.Eng.Sun.COM> cmcmanis@sun.UUCP (Chuck McManis) writes:
>I wrote : 
>>Why don't you use SetWindowTitle()?
>
>In article <d2YG02GD32Hm01@amdahl.uts.amdahl.com> (Dave Lowrey) writes:
>>I need to get the address of the current title, as well as
>>setting a new title.
>>
>>So I guess I am asking if it is safe to access this info
>>without any locking.
>
>Hmmmm, why do I get the feeling that you aren't doing something that 
>one my consider "normal" programming practice? :-) 

That's why I am asking these questions. I would like to remain
"normal" (Whatever that means). :-)

>
>So to be completely blunt and open about this :
>
>       You opened a window, so you have a pointer to the window...

You assume wrong. The "shell" has opened the window, so I don't
own it.

The program I am writing puts the Current Directory into the
title bar. It works now, without ANY locking, but I suspect that
I am inviting trouble by not preventing other processes from accessing
the data.

>
>By the way, I couldn't find any reference in IntuitionBase that had
>to do with titles anyway. Where were you looking?
>
You are correct. But, in intutitonbase.h (I think, tne I am at work,
and the RKM is at home), it says that whenever referencing IntuitionBase,
you should use LockIbase and UnlockIbase. I access IntuitionBase to
get the pointer to the current screen.

-- 
"What is another word  |  Dave Lowrey    | [The opinions expressed MAY be
 for 'Thesaurus'?"     |  Amdahl Corp.   | those of the author and are not
                       |  Houston, Texas | necessarily those of his
   Steven Wright       |  amdahl!dwl10   | employer]   (`nuff said!)

new@udel.EDU (Darren New) (06/10/89)

I have been doing something like this with a program I wrote called yatbc,
(yet another title bar clock) which puts the time and free mem in
the title bar of the window that is active when it starts.
This is a real hack, as it does no checking. It simply grabs the
active window pointer out of the IntuitionBase and calls SetTitle with
that pointer every time the title string changes. I wrote it mainly
because while developing I always have the one window open and
I don't like the screen-breaking that occurs with separate-window
clocks. I've never had any problem doing this, even when I accidentally
close the window and have to reopen another. The process sticks around,
but maybe Intuition is checking that it's args are correct or something
because I've never known it to cause a crash. If anyone wants this,
EMail me. Hope this helps... -- Darren

cmcmanis%pepper@Sun.COM (Chuck McManis) (06/10/89)

In article <1aY.02kv33t701@amdahl.uts.amdahl.com> (Dave Lowrey) writes:
>You assume wrong. The "shell" has opened the window, so I don't
>own it.
>
>The program I am writing puts the Current Directory into the
>title bar. It works now, without ANY locking, but I suspect that
>I am inviting trouble by not preventing other processes from accessing
>the data.

You are correct, you are inviting trouble. Unfortunately there is
no locking mechanisim possible to prevent the trouble you will get
into because there is no way to tell the process that owns the window
that it can't diddle with the window title. Many shells such as WShell
do so, and you will crash them faster than a MiG in Paris. 

As for getting the screen, you realize you can get the window from the
the console.device? Does your program run "under" this Shell? If so then
your stdin should be a lock on the console device and you can query it
to have it return you a pointer to it's window. That may be easier than
querying ibase too. 

You might also want to check out a copy of Wshell and look at the 
title functions it supports, all in all they are pretty wizzy. Of
course as the Shell it thinks it owns the titlebar :-)


--Chuck McManis
uucp: {anywhere}!sun!cmcmanis   BIX: cmcmanis  ARPAnet: cmcmanis@sun.com
These opinions are my own and no one elses, but you knew that didn't you.
"A most excellent barbarian ... Genghis Kahn!"