Handling IRPs 6: Asynchronous I/O Responses

来源:互联网 发布:金蝶软件连接数据库 编辑:程序博客网 时间:2024/05/16 10:31

Asynchronous I/OResponses

A driver should return STATUS_PENDING from a dispatch routine when it cannot complete an I/O request synchronously in a timely manner. Understanding when to return STATUS_PENDING is a problem for many driver writers.

A driver must return STATUS_PENDING if:

·         Its dispatch routine for an IRP might return before the IRP is completed.

·         It completes the IRP on another thread.

·         The dispatch routine cannot determine the IRP’s completion status before it returns.

 

The driver must call the IoMarkIrpPending macro before it releases control of the IRP and before it returns STATUS_PENDING.IoMarkIrpPending sets the SL_PENDING_RETURNED bit in the Control field of the current I/O stack location. Each time an I/O stack location is completed, the I/O Manager copies the value of this bit to theIrp->PendingReturned field in the IRP header, as Figure 5 shows.

 

Figure 5. Propagating the pending bit

In Figure 5, Driver C’s call to theIoMarkIrpPending macro sets the SL_PENDING_RETURNED bit in the Control field of Driver C’s I/O stack location. When Driver C completes the IRP, the I/O Manager changes the IRP stack pointer to point to driver B and propagates the value of the SL_PENDING_RETURNED bit to thePendingReturned field in the IRP header.