InterlockedTestExchange

The InterlockedTestExchange function is an interlocked function that performs a conditional setting of a variable.

Syntax

LONG WINAPI InterlockedTestExchange(LPLONG Target, LONG OldValue, LONG NewValue);

At a Glance

Header file: Winbase.h
Component: coremain
Platforms: H/PC
Windows CE versions: 1.0 and later

Parameters

Target
Address of the LONG variable to check and set.
OldValue
Value to check against.
NewValue
Value to set to conditionally.

Return Values

Returns the value pointed to by Target at the time of the call — that is, the old value.

Remarks

The InterlockedTestExchange function is an interlocked function—in other words, it can be considered atomic. It checks to see if the value pointed to by Target is equal to OldValue. If so, it sets Target to NewValue. Since InterlockedTestExchange returns the "old" value pointed to by Target, if the return value is OldValue, then InterlockedTestExchange succeeded and set the value pointed to by Target to NewValue. Otherwise, it failed.