InterlockedCompareExchangePointer function

The InterlockedCompareExchangePointer routine performs an atomic operation that compares the input pointer value pointed to by Destination with the pointer value Comparand.

Syntax

PVOID InterlockedCompareExchangePointer(
  _Interlocked_operand_ PVOID *Destination,
  PVOID                       Exchange,
  PVOID                       Comperand
);

Parameters

Destination

A pointer to a PVOID value. If (Destination) = Comparand, then the routine sets (Destination) to Exchange.

Exchange

Specifies the PVOID value to set (*Destination) to.

Comperand

TBD

Return Value

InterlockedCompareExchangePointer returns the original value of the pointer at *Destination (that is, the value of this pointer at entry to the routine).

Remarks

If Comparand is equal to *Destination, then *Destination is set to equal Exchange. Otherwise, *Destination is unchanged.

InterlockedCompareExchangePointer provides a fast, atomic way to synchronize the testing and updating of a pointer variable that is shared by multiple threads. If the input value pointed to by Destination equals the value of Comparand, the value pointed to by Destination is set to the value of Exchange.

InterlockedCompareExchangePointer is designed for speed and, typically, is implemented inline by a compiler. InterlockedCompareExchangePointer is atomic only with respect to other InterlockedXxx calls. It does not use a spin lock and can be safely used on pageable data.

The InterlockedCompareExchangePointer routine is atomic only with respect to other InterlockedXxx calls.

Interlocked operations cannot be used on non-cached memory.

Requirements

   
Windows version Available starting with Windows 2000.
Target Platform Desktop
Header wdm.h (include Wdm.h, Ntddk.h, Ntifs.h, Miniport.h)
IRQL Any level

See Also

InterlockedCompareExchange

InterlockedExchange

InterlockedExchangePointer