IO_CSQ_ACQUIRE_LOCK callback function (wdm.h)

The CsqAcquireLock routine is used by the system to acquire the lock for a driver-implemented, cancel-safe IRP queue.

Syntax

IO_CSQ_ACQUIRE_LOCK IoCsqAcquireLock;

void IoCsqAcquireLock(
  [in]  PIO_CSQ Csq,
  [out] PKIRQL Irql
)
{...}

Parameters

[in] Csq

Pointer to the IO_CSQ structure for the cancel-safe IRP queue.

[out] Irql

Pointer to a variable that the CsqAcquireLock routine can use to store the current IRQL. The system passes the stored value CsqReleaseLock when it releases the lock.

Return value

None

Remarks

The driver specifies the CsqAcquireLock routine for a cancel-safe IRP queue when it initializes the queue's IO_CSQ structure. The driver specifies the routine as the CsqAcquireLock parameter of IoCsqInitialize or IoCsqInitializeEx when it initializes IO_CSQ. For more information, see Cancel-Safe IRP Queues.

The system calls this routine to acquire a lock on the driver's IRP queue before attempting to insert or remove an IRP from the queue. The system calls the CsqReleaseLock routine to release the lock.

If the driver uses a spin lock to implement locking for the queue, it must store the current IRQL for when it releases the spin lock. The system passes a pointer to an IRQL variable that the driver can use to store the current IRQL. The system passes the stored value as the Irql parameter to CsqReleaseLock when it releases the lock. Otherwise the driver can ignore the Irql parameter. For information about spin locks, see Spin Locks.

Drivers can use any locking mechanism to lock the queue, such as mutexes. For more information about mutexes, see Mutex Objects.

Examples

To define a CsqAcquireLock callback routine, you must first provide a function declaration that identifies the type of callback routine you're defining. Windows provides a set of callback function types for drivers. Declaring a function using the callback function types helps Code Analysis for Drivers, Static Driver Verifier (SDV), and other verification tools find errors, and it's a requirement for writing drivers for the Windows operating system.

For example, to define a CsqAcquireLock callback routine that is named MyCsqAcquireLock, use the IO_CSQ_ACQUIRE_LOCK type as shown in this code example:

IO_CSQ_ACQUIRE_LOCK MyCsqAcquireLock;

Then, implement your callback routine as follows:

_Use_decl_annotations_
VOID 
 MyCsqAcquireLock(
    PIO_CSQ  Csq,
    PKIRQL  Irql
    )
  {
      // Function body
  }

The IO_CSQ_ACQUIRE_LOCK function type is defined in the Wdm.h header file. To more accurately identify errors when you run the code analysis tools, be sure to add the _Use_decl_annotations_ annotation to your function definition. The _Use_decl_annotations_ annotation ensures that the annotations that are applied to the IO_CSQ_ACQUIRE_LOCK function type in the header file are used. For more information about the requirements for function declarations, see Declaring Functions by Using Function Role Types for WDM Drivers. For information about _Use_decl_annotations_, see Annotating Function Behavior.

Requirements

Requirement Value
Target Platform Desktop
Header wdm.h (include Wdm.h, Ntddk.h, Ntifs.h)
IRQL See Remarks section.

See also

CsqCompleteCanceledIrp

CsqInsertIrp

CsqInsertIrpEx

CsqPeekNextIrp

CsqReleaseLock

CsqRemoveIrp

IO_CSQ

IoCsqInitialize

IoCsqInitializeEx

IoCsqInsertIrp

IoCsqInsertIrpEx

IoCsqRemoveIrp

IoCsqRemoveNextIrp