Export (0) Print
Expand All
Expand Minimize

KeAcquireSpinLock routine

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

Syntax


VOID KeAcquireSpinLock(
  _In_   PKSPIN_LOCK SpinLock,
  _Out_  PKIRQL OldIrql
);

Parameters

SpinLock [in]

Pointer to an initialized spin lock for which the caller provides the storage.

OldIrql [out]

Pointer to a variable that is set to the current IRQL when this call occurs.

Return value

None

Remarks

KeAcquireSpinLock first resets the IRQL to DISPATCH_LEVEL and then acquires the lock. The previous IRQL is written to OldIrql after the lock is acquired.

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

Most drivers use a local variable to store the old IRQL value. A driver can also use a shared memory location, such as a global variable, but the driver must not use the same location for two different locks. Otherwise, a race condition can occur.

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:

  • The code within a critical region guarded by an spin lock must neither be pageable nor make any references to pageable data.

  • The code within a critical region guarded by a spin lock can neither call any external function that might access pageable data or raise an exception, nor can it generate any exceptions.

  • The caller should release the spin lock with KeReleaseSpinLock as quickly as possible.

Attempting to acquire a spin lock recursively is guaranteed to cause a deadlock. For more information about spin locks, see Spin Locks.

Requirements

Version

Available starting with Windows 2000.

Header

Wdm.h (include Wdm.h, Ntddk.h, or Ntifs.h)

Library

Hal.lib

IRQL

<= DISPATCH_LEVEL

DDI compliance rules

IrqlKeDispatchLte, MarkingQueuedIrps, SpinLock, SpinLockDpc, SpinlockRelease, SpinLockSafe, ReqSendWhileSpinlock, Spinlock(kmdf), SpinlockDpc(kmdf), SpinlockRelease(kmdf), HwStorPortProhibitedDDIs, SpinLock(storport), SpinLockDpc(storport), SpinLockRelease(storport), SpinLockSafe(storport)

See also

KeAcquireInStackQueuedSpinLock
KeAcquireSpinLockAtDpcLevel
KeInitializeSpinLock
KeReleaseSpinLock

 

 

Send comments about this topic to Microsoft

Show:
© 2014 Microsoft