Bewerken

Delen via


IoReleaseRemoveLockAndWait macro (wdm.h)

The IoReleaseRemoveLockAndWait routine releases a remove lock that the driver acquired in a previous call to IoAcquireRemoveLock, and waits until all acquisitions of the lock have been released.

Syntax

void IoReleaseRemoveLockAndWait(
  [in]  RemoveLock,
  [in]  Tag
);

Parameters

[in] RemoveLock

Pointer to an IO_REMOVE_LOCK structure that the caller passed in a previous call to IoAcquireRemoveLock.

[in] Tag

Pointer to a caller-supplied tag that was passed in a previous call to IoAcquireRemoveLock.

If a driver specified a Tag when it acquired the lock, the driver must specify the same Tag when releasing the lock.

If the call to IoAcquireRemoveLock did not specify a Tag, then this parameter is NULL.

Return value

None

Remarks

A driver typically calls this routine in its dispatch code for an IRP_MN_REMOVE_DEVICE request. To allow queued I/O requests to complete, each driver should call IoReleaseRemoveLockAndWait after it passes the remove IRP to the next-lower driver, and before it releases memory, calls IoDetachDevice, or calls IoDeleteDevice. The IoReleaseRemoveLockAndWait routine waits for the bus driver to cancel any IRPs that might be outstanding (for example, an IRP_MN_WAIT_WAKE IRP).

A driver must acquire the remove lock before calling IoReleaseRemoveLockAndWait. Typically, a driver calls IoAcquireRemoveLock early in its DispatchPnp routine, before the switch statement. As a result, the lock is acquired for each PnP operation, including the acquisition that is required before calling IoReleaseRemoveLockAndWait in the code that handles IRP_MN_REMOVE_DEVICE.

To release a lock from code other than the IRP_MN_REMOVE_DEVICE dispatch code, use IoReleaseRemoveLock.

After IoReleaseRemoveLockAndWait has been called for a particular remove lock, subsequent calls to IoAcquireRemoveLock for the same remove lock will fail. IoReleaseRemoveLockAndWait does not return until all outstanding acquisitions of the remove lock have been released.

After IoReleaseRemoveLockAndWait returns, the driver should consider the device to be in a state in which it is ready to be removed and cannot perform I/O operations. Therefore, the driver must not call the IoInitializeRemoveLock routine to re-initialize the remove lock. Violation of this rule while the driver is being verified by Driver Verifier will result in a bug check.

For more information, see Using Remove Locks.

Requirements

Requirement Value
Minimum supported client Available starting with Windows 2000.
Target Platform Desktop
Header wdm.h (include Wdm.h, Ntddk.h, Ntifs.h)
Library NtosKrnl.lib
DLL NtosKrnl.exe
IRQL PASSIVE_LEVEL
DDI compliance rules IoReleaseRemoveLockAndWaitOutsideRemoveDevice(wdm), RemoveLock(wdm), RemoveLockCheck(wdm), RemoveLockMnRemove(wdm), RemoveLockMnRemove2(wdm), RemoveLockReleaseCleanup(wdm), RemoveLockReleaseClose(wdm), RemoveLockReleaseCreate(wdm), RemoveLockReleaseDeviceControl(wdm), RemoveLockReleaseInternalDeviceControl(wdm), RemoveLockReleasePower(wdm), RemoveLockReleaseRead(wdm), RemoveLockReleaseShutdown(wdm), RemoveLockReleaseSystemControl(wdm), RemoveLockReleaseWrite(wdm)

See also

DispatchPnp

IRP_MN_WAIT_WAKE

IoAcquireRemoveLock

IoDeleteDevice

IoDetachDevice

IoInitializeRemoveLock

IoReleaseRemoveLock