[comp.sys.mac.programmer] VBL Tasks etc

wras@walt.cc.utexas.edu (Steve Mariotti) (05/04/90)

I know this is probably a silly question, but say that a VBL task is installed
in the application heap.  If Multifinder is running, doesn't this present big
huge tremenous problems when this application is switched out?  Should the
task itself keep track of which A5 is current?  If so, whats the best way to
keep it in the task?

Are there advantages to just trying to install it in the system heap and then
remove it from there?  It doesn't seem like that would be necessary, but 
then I don't want it to come to a bone-shattering crash when multifinder
brings another app to the foreground.

Also, are there any code fragments floating about which demonstrate a self-
aware VBL task?  

Thanks a lot.

Ste
 ______  _____________________________________________________________________
| ____ |   Steve Mariotti -- University of Texas at Austin -- CS Undergrad(e) |
||    || ---------------------------------------------------------------------|
||    || wras@ccwf.cc.utexas.edu | csar242@ix1.cc.utexas.edu | AOL:SteveM16   |
| ---- | ---------------------------------------------------------------------|
|.  -- |          "Wouldn't be prudent, not at this juncture."                |
|______| ---------------------------------------------------------------------'
|______|          function introspanish(time : longint) : pain;

tim@hoptoad.uucp (Tim Maroney) (05/07/90)

In article <29470@ut-emx.UUCP> wras@walt.cc.utexas.edu (Steve Mariotti) writes:
>I know this is probably a silly question, but say that a VBL task is installed
>in the application heap.  If Multifinder is running, doesn't this present big
>huge tremenous problems when this application is switched out?  Should the
>task itself keep track of which A5 is current?  If so, whats the best way to
>keep it in the task?

If it's in the application heap, it only runs when the application is
getting time.  However, you can't count on A5 being correct, since
someone that you're interrupting may have changed it.  Instead, use
CurrentA5 -- the new SetCurrentA5 and SetA5 inline routines in MPW C
3.x work well to save the current A5, set the current A5, and then
restore the original A5 when you're done.  On more crufty compilers you
may have to use inline assembler.

>Are there advantages to just trying to install it in the system heap and then
>remove it from there?  It doesn't seem like that would be necessary, but 
>then I don't want it to come to a bone-shattering crash when multifinder
>brings another app to the foreground.

If you install it in the system heap, it will run all the time, not
just when your application is switched in, and you'd better be sure to
get rid of it when your application completes.  You can't use CurrentA5
for obvious reasons.  Instead, make a data structure whose first
element is a VBL queue element.  Put your A5 (or better, just a pointer
to whatever data you need to access, forgetting about A5) into the
structure in the new field you've created for that purpose. When the
VBL is called, register A0 contains a pointer to your structure.
-- 
Tim Maroney, Mac Software Consultant, sun!hoptoad!tim, tim@toad.com

"He goes on about the wailing and gnashing of teeth.  It comes in one
 verse after another, and it is quite manifest to the reader that there
 is a certain pleasure in contemplating the wailing and gnashing of
 teeth, or else it would not occur so often."
	-- Bertrand Russell, "Why I Am Not a Christian"