The InterlockedTestExchange function is an interlocked function that performs a conditional setting of a variable.
LONG WINAPI InterlockedTestExchange(LPLONG Target, LONG OldValue, LONG NewValue);
Header file: | Winbase.h |
Component: | coremain |
Platforms: | H/PC |
Windows CE versions: | 1.0 and later |
Returns the value pointed to by Target at the time of the call — that is, the old value.
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.