[comp.sys.mac.programmer] Can I/O Completion routine call 'GetRequest'??

rmitchel@bbn.com (Rob Mitchell) (04/10/91)

    I've created a list of 20 parameter blocks and queued them into a 
    pseudo "free" list (at the start of my program).  Each has a "state"
    of FREE.  I call ATP's 'GetRequest' asynchronously once using a globally 
    created param block (should it really be a global or one of the "free" 
    ones?).

    When Mac receives a TReq, my I/O Completion routine assigns reg. A0
    (which contains address of current param block) to local variable and
    set param's "state" to INCOMING.  

    What I need to do now is queue another 'GetRequest' from my I/O
    Completion routine.  Can I call I use a different "free" element
    and make the 'GetRequest' call from my I/O Completion routine?
    I'm not allocating/moving any memory, right?  GetRequest should
    just assign a bunch of pointers, right?  It probably doesn't move
	or allocate any memory, right??

    How else can I have at least one 'GetRequest' always outstanding
    at *any* given time?????

    Thanks in advance!!!!


Rob Mitchell                            Advanced Simulation Division
Unix & Macintosh Engineer               BBN Systems & Technologies
Internet: rmitchel@vax.bbn.com          33 Moulton Street   MS: 8/C
Primary Dwelling:   617-873-4041        Cambridge, MA  02138
Secondary Dwelling: 617-873-4071
FAX:                617-873-4315

These opinions are mine and mine only.  They do not represent BBNs' opinions.

peirce@outpost.UUCP (Michael Peirce) (04/21/91)

In article <63618@bbn.BBN.COM>, rmitchel@bbn.com (Rob Mitchell) writes:
> 
> 
>     I've created a list of 20 parameter blocks and queued them into a 
>     pseudo "free" list (at the start of my program).  Each has a "state"
>     of FREE.  I call ATP's 'GetRequest' asynchronously once using a globally 
>     created param block (should it really be a global or one of the "free" 
>     ones?).
> 
>     When Mac receives a TReq, my I/O Completion routine assigns reg. A0
>     (which contains address of current param block) to local variable and
>     set param's "state" to INCOMING.  
> 
>     What I need to do now is queue another 'GetRequest' from my I/O
>     Completion routine.  Can I call I use a different "free" element
>     and make the 'GetRequest' call from my I/O Completion routine?
>     I'm not allocating/moving any memory, right?  GetRequest should
>     just assign a bunch of pointers, right?  It probably doesn't move
> 	or allocate any memory, right??
> 
>     How else can I have at least one 'GetRequest' always outstanding
>     at *any* given time?????
> 
>     Thanks in advance!!!!

Sounds like you have the right idea.  Calling PGetRequest from a completion
routine is fine and a common approach found in many programs.  And
it's the only way to implement programs that live only at interrupt
level.  Just be doubly sure that that your parameter blocks are really
free when you reuse them!

Good luck with your project.


--  Michael Peirce         --   outpost!peirce@claris.com
--  Peirce Software        --   Suite 301, 719 Hibiscus Place
--  Macintosh Programming  --   San Jose, California 95117
--           & Consulting  --   (408) 244-6554, AppleLink: PEIRCE

davids@mondo.engin.umich.edu (David Snearline) (04/22/91)

In article <0B010004.nn2ddd@outpost.UUCP> peirce@outpost.UUCP writes:
>
>In article <63618@bbn.BBN.COM>, rmitchel@bbn.com (Rob Mitchell) writes:
>> 
>> 
>>     I've created a list of 20 parameter blocks and queued them into a 
>>     pseudo "free" list (at the start of my program).  Each has a "state"
>>     of FREE.  I call ATP's 'GetRequest' asynchronously once using a globally 
>>     created param block (should it really be a global or one of the "free" 
>>     ones?).
>> 
>>     When Mac receives a TReq, my I/O Completion routine assigns reg. A0
>>     (which contains address of current param block) to local variable and
>>     set param's "state" to INCOMING.  
>> 
>>     What I need to do now is queue another 'GetRequest' from my I/O
>>     Completion routine.  Can I call I use a different "free" element
>>     and make the 'GetRequest' call from my I/O Completion routine?
>>     I'm not allocating/moving any memory, right?  GetRequest should
>>     just assign a bunch of pointers, right?  It probably doesn't move
>> 	or allocate any memory, right??
>> 
>>     How else can I have at least one 'GetRequest' always outstanding
>>     at *any* given time?????
>> 
>>     Thanks in advance!!!!
>
>Sounds like you have the right idea.  Calling PGetRequest from a completion
>routine is fine and a common approach found in many programs.  And
>it's the only way to implement programs that live only at interrupt
>level.  Just be doubly sure that that your parameter blocks are really
>free when you reuse them!
>
>Good luck with your project.

Is it possible to re-use the same parameter block from your completion
routine?  ie. Has IODone already called Dequeue on your parameter block
by the time it calls your completion routine?

Thanks in advance.

--
David Snearline
University of Michigan Engineering
davids@mondo.engin.umich.edu

kurash@chocorua (Mark Valence) (04/23/91)

>Is it possible to re-use the same parameter block from your completion
>routine?  ie. Has IODone already called Dequeue on your parameter block
>by the time it calls your completion routine?
>

The quick answer: Yes, it's OK.

The longer answer:

In general, the fact that the call is completing means that the parameter
block is NOT on the queue.  The IODone removes queued calls from a driver's
queue and THEN the driver is handed the parameter block (queue element, pb).

The only way a param block gets queued in the first place is if you make the
call asynchronously, AND, when the call is made, the driver is busy with
another call.  When that call completes, it calls IODone, which dequeues the
(async) block, and calls the driver with that block.

In ATP, details are a bit different.  ATP almost never calls IODone - it
handles its driver queue all by itself, placing the parameter block on
one of many internal queues (yes, plural).  Because it doesn't use IODone,
ATP also handles calling your IOCompletion routine.  First, it removes
your pb from whichever internal queue it is on, and then it calls your
completion routine.

Well, that's a very sketchy description, but hopefully it answers the
question.  If you want more details, e-mail.  I don't know anyone at
Apple, so this is certainly not official word, just the musings of a
hacker.



>Thanks in advance.
>
Your welcome in arrears.

>--
>David Snearline
>University of Michigan Engineering
>davids@mondo.engin.umich.edu

Mark.

rmitchel@bbn.com (Rob Mitchell) (05/04/91)

davids@mondo.engin.umich.edu (David Snearline) writes:

>In article <0B010004.nn2ddd@outpost.UUCP> peirce@outpost.UUCP writes:
>>
>>In article <63618@bbn.BBN.COM>, rmitchel@bbn.com (Rob Mitchell) writes:
>>> [my old stuff]
>> [other old stuff]

>Is it possible to re-use the same parameter block from your completion
>routine?  ie. Has IODone already called Dequeue on your parameter block
>by the time it calls your completion routine?

    I've tried to use the same param block from an I/O completion
    routine, but it bombs out with SCSI dismount errors???  I know
    it sounds strange, but that's what MacsBug "ip" command in
    telling me.

    What I've done is when IO completion is called, I set a flag in
    PB.  Later, during NULL events, I scan message queue for this
    flag and process a request or send a response (depends on 
    AppleTalk code) to finish off whatever the PB was originally
    doing.


Rob Mitchell                            Advanced Simulation Division
Unix & Macintosh Engineer               BBN Systems & Technologies
Internet: rmitchel@vax.bbn.com          33 Moulton Street   MS: 8/C
Primary Dwelling:   617-873-4041        Cambridge, MA  02138
Secondary Dwelling: 617-873-4071
FAX:                617-873-4315

These opinions are mine and mine only.  They do not represent BBNs' opinions.

urlichs@smurf.sub.org (Matthias Urlichs) (05/05/91)

In comp.sys.mac.programmer, article <64025@bbn.BBN.COM>,
  rmitchel@bbn.com (Rob Mitchell) writes:
< 
<     I've tried to use the same param block from an I/O completion
<     routine, but it bombs out with SCSI dismount errors???  I know
<     it sounds strange, but that's what MacsBug "ip" command in
<     telling me.
< 
In that case, you're doing something wrong because other people have used
that method without running into strange problems -- at least not after
fixing all the bugs commonly lurking in interrupt-callable code.  :-(

Maybe you're trashing a register or some global?

<     What I've done is when IO completion is called, I set a flag in PB.
The flag is already there; it's called "ioResult".  > 0 means the operation is
still in progress.

NB: Don't forget that MacsBug messages aren't very helpful when deep inside
the ROM. You can get a better idea as to what the code you're looking at is
supposed to do by looking up the address in the ROM map for your machine.
(Look in the "ROM Maps" folder in your MPW directory.)
-- 
Matthias Urlichs -- urlichs@smurf.sub.org -- urlichs@smurf.ira.uka.de     /(o\
Humboldtstrasse 7 - 7500 Karlsruhe 1 - FRG -- +49-721-621127(0700-2330)   \o)/