[comp.sys.mac.programmer] Communication between asynchronous calls and the application

d6maca@dtek.chalmers.se. (Martin Carlberg) (12/17/89)

Hi!

I have problem telling my application that a asynchronous call has completed.
The problem is that I need to do some Memory Manager calls. I can use a flag
and check it in the eventloop, but it's not good. I did try to post events,
but when multifinder is running I loose some of them.

Any ideas?

- Martin Carlberg
- Chalmers University of Technology, Gothenburg, Sweden

tim@hoptoad.uucp (Tim Maroney) (12/18/89)

In article <613@vice2utc.chalmers.se> d6maca@dtek.chalmers.se
(Martin Carlberg) writes:
>Hi!

Greetings, earthling.

>I have problem telling my application that a asynchronous call has completed.
>The problem is that I need to do some Memory Manager calls. I can use a flag
>and check it in the eventloop, but it's not good. I did try to post events,
>but when multifinder is running I loose some of them.

I try to avoid posting my own events unless they're absolutely
necessary.  Probably the best way to do this is by checking the
parameter block itself.  As soon as you make the async call, ioResult
is set to 1 (one); when the call completes, ioResult is set to zero (0,
noErr) or negative (error).  So you can check the parameter block
itself in your main event loop to find out when the call completes.
Presumably you have this parameter block stored as a global somewhere.
If you do this, you may very well not even need a completion routine.

If you're really committed to using a separate flag global, then you
need to be aware that the globals register (A5) may not be correct when
your routine completes.  You can store a copy of A5 in your parameter
block in an unused field; your completion routine saves the A5 that's
active when it gets called, sets A5 to be the A5 in the parameter
block, sets the flag, and finally restores the previous A5 that it
saved.  It's easier to save a pointer to your flag, so you don't use
the globals register and can ignore A5: stash a pointer to the flag in
an unused field of the parameter block, then use that pointer to set
the flag during your completion routine.

And in case you didn't know, your completion routine gets passed a
pointer to the parameter block in register A0.
-- 
Tim Maroney, Mac Software Consultant, sun!hoptoad!tim, tim@toad.com

"I was brought up in the other service; but I knew from the first that the
 Devil was my natural master and captain and friend.  I saw that he was in
 the right, and that the world cringed to his conqueror only from fear."
    - Shaw, "The Devil's Disciple"