Some routines provide a callback mechanism. This is a way to schedule a function to be called when a condition is met. Typical conditions for which callback functions are set up include:
When a transfer has completed
When a resource might become available
When a time-out period has expired
Transfer completion callbacks perform the tasks usually done in an interrupt service routine.
In some sense, callback functions are similar to entry points. The functions that allow callbacks expect the callback function to perform certain tasks. In the case of DMA routines, a callback function must return a value indicating whether the callback function needs to be rescheduled in case of a failure.
Callback functions execute as a separate interrupt thread and must handle all the usual multithreading issues.
A driver must cancel all scheduled callback functions before detaching a device.