InterlockedCompareExchange

PVOID
    InterlockedCompareExchange(
        IN OUT PVOID
 *Destination,
        IN PVOID Exchange,
        IN PVOID Comperand
        );

InterlockedCompareExchange compares a pointer value (Comperand) with a destination pointer value (Destination). If the values are equal, then a third pointer value (Exchange) is stored in the destination. Otherwise, no operation is performed. The compare and exchange operations are performed in an atomic operation.

Parameters

Destination
Points to a destination value that will be compared and possibly replaced.
Exchange
Points to the value that will replace the destination value if the comparison results in equality.
Comperand
Points to the value with which the destination value will be compared.

Return Value

InterlockedCompareExchange returns the original destination value.

Comments

InterlockedCompareExchange provides an atomic way to test a value and update it if the test passes. This routine is implemented inline by the compiler when appropriate and possible. It does not require a spin lock and can therefore be safely used on pageable data.

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

Callers of InterlockedCompareExchange run at any IRQL.

See Also

InterlockedIncrement, InterlockedDecrement, InterlockedExchange