InterlockedTestExchange

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

At a Glance

Header file: Winbase.h
Windows CE versions: 1.0 and later

Syntax

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

Parameters

Target

[in] Pointer to the LONG variable to check and set.

OldValue

[in] Specifies the value to check against.

NewValue

[in] Specifies the value to set to conditionally.

Return Values

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

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.