Synchronizing Driver Activities, Using VCKernel.lib

Code that references the same objects that a driver’s interrupt service routine (ISR) references ¾ typically structures and device registers ¾ must be synchronized to avoid simultaneous attempts at referencing the same object. Likewise, code that references the same objects that the driver’s deferred procedure call (DPC) function references ¾ typically the frame buffer ¾ must be synchronized.

Kernel-mode drivers normally run at an IRQL of PASSIVE_LEVEL. When a device interrupt occurs, the IRQL increases to the device’s IRQL while the ISR executes. The ISR acknowledges the interrupt and schedules the execution of a DPC function. The DPC function finishes servicing the interrupt, typically by copying frame buffer data. It executes at an IRQL of DISPATCH_LEVEL, which is between PASSIVE_LEVEL and the device’s level.

Video capture drivers using VCKernel.lib should use the VC_SynchronizeExecution function to synchronize references to objects that the device’s ISR uses. The function uses a spin lock and the device’s IRQL to maintain exclusive use of the referenced object.

Drivers should use the VC_SynchronizeDPC function to synchronize references to objects that the device’s DPC function uses. The VC_SynchronizeDPC function uses a spin lock and the DISPATCH_LEVEL IRQL to maintain exclusive use of the referenced object.

Use of VC_SynchronizeExecution and VC_SynchronizeDPC ensures that multiple processors cannot simultaneously reference the same object, and that lower-priority code executing on the current processor cannot obtain access to the object.

For more information about spin locks, and IRQLs, see the Kernel-Mode Drivers Design Guide.