Queued Spin Locks

Queued spin locks are a variant of spin locks that are more efficient for high contention locks on multiprocessor machines. On multiprocessor machines, using queued spin locks guarantees that processors acquire the spin lock on a first-come first-served basis. Drivers for Windows XP and later versions of Windows should use queued spin locks instead of ordinary spin locks.

The driver supplies storage for the spin lock, and initializes it with KeInitializeSpinLock. The driver uses KeAcquireInStackQueuedSpinLock to acquire the queued spin lock, and KeReleaseInStackQueuedSpinLock to release it.

The driver allocates a KLOCK_QUEUE_HANDLE structure that it passes by pointer to KeAcquireInStackQueuedSpinLock. The driver passes the same structure by pointer to KeReleaseInStackQueuedSpinLock when it releases the spin lock. Drivers should normally allocate the structure on the stack each time they acquire the lock.

Drivers must not mix calls to the queued spin lock routines and the ordinary KeXxxSpinLock routines on the same spin lock.

If the driver is already at IRQL = DISPATCH_LEVEL, it can call KeAcquireInStackQueuedSpinLockAtDpcLevel and KeReleaseInStackQueuedSpinLockFromDpcLevel instead.