Handling Asynchronous I/O
If you design any of your driver routines to execute asynchronously, you must provide a mechanism for the driver to complete the requests. Some examples of routines that you might use are the following:
-
Completion routines:
Completion routines are provided by Device Manager clients to let the Device Manager notify the client when an I/O process is finished.
-
Interrupt handlers:
If the driver serves a hardware device that generates interrupts, you can create an interrupt handler that responds to these interrupts. The interrupt handler must clear the source of the interrupt and return as quickly as possible. For more information about interrupts and how to install an interrupt handler, see
Interrupt Management.
Clients of the Device Manager that make asynchronous calls should observe these guidelines when using asynchronous routines:
-
Once you pass a parameter block to an asynchronous routine, it is out of your control. You should not examine or change the parameter block until the completion routine is called because you have no way of knowing the state of the parameter block.
-
Do not dispose of or reuse a parameter block until the asynchronous request is completed. For example, if you declare the parameter block as a local variable, the function cannot return until the request is complete because local variables are allocated on the stack and released when a function returns.
-
Use a completion routine to determine when an asynchronous routine has completed, rather than polling the
ioResult
field of the parameter block. Polling the
ioResult
field is not efficient and defeats the purpose of asynchronous operation.
© 1999 Apple Computer, Inc. (Last Updated 26 March 99)