Previous Next

KeAcquireSpinLock

The KeAcquireSpinLock routine acquires a spin lock so the caller can synchronize access to shared data in a multiprocessor-safe way by raising IRQL.

VOID 
  KeAcquireSpinLock(
    IN PKSPIN_LOCK  SpinLock,
    OUT PKIRQL  OldIrql
    );

Parameters

SpinLock
Pointer to an initialized spin lock for which the caller provides the storage.
OldIrql
Pointer to a variable that is set to the current IRQL when this call occurs.

Return Value

None

Headers

Declared in wdm.h and ntddk.h. Include wdm.h or ntddk.h.

Comments

Drivers for Windows XP and later should use the more efficient and reliable queued spin locks, which are acquired by the KeAcquireInStackQueuedSpinLock routine.

The current IRQL is saved in OldIrql. Then, the current IRQL is reset to DISPATCH_LEVEL, and the specified spin lock is acquired.

The OldIrql value must be specified when the spin lock is released with KeReleaseSpinLock.

Spin locks can cause serious problems if not used judiciously. In particular, no deadlock protection is performed and dispatching is disabled while the spin lock is held. Therefore:

Callers of KeAcquireSpinLock must be running at IRQL <= DISPATCH_LEVEL.

See Also

KeAcquireInStackQueuedSpinLock, KeAcquireSpinLockAtDpcLevel, KeInitializeSpinLock, KeReleaseSpinLock