Spin locks are Kernel-defined, kernel-mode-only synchronization mechanisms, exported as an opaque type: KSPIN_LOCK. A spin lock can be used to protect shared data or resources from simultaneous access by routines that can execute concurrently and at raised IRQL in Windows NT SMP machines.
Many NT components use spin locks, including NT drivers. Any kind of NT driver might use one or more executive spin locks. For example, most NT file systems use an interlocked work queue in the FSD’s device extension to store IRPs that are processed both by the file system’s worker-thread callback routines and by the FSD. An interlocked work queue is protected by an executive spin lock, used to resolve contention among the FSD trying to insert IRPs into the queue and any threads simultaneously trying to remove IRPs. As another example, the system floppy controller driver uses two executive spin locks. One executive spin lock protects an interlocked work queue shared with this driver’s device-dedicated thread; the other protects a timer object shared by three driver routines.
Every NT driver that has an ISR uses an interrupt spin lock to protect any data or hardware shared between its ISR and its SynchCritSection routine(s) that are usually called from a driver’s StartIo and DpcForIsr routines. An interrupt spin lock is associated with the set of interrupt objects created when such a driver calls IoConnectInterrupt, as described in Chapter 3.
The following subsections explain these guidelines in more detail.