_InterlockedCompareExchangePointer Intrinsic Functions
The new home for Visual Studio documentation is Visual Studio 2017 Documentation on docs.microsoft.com.
The latest version of this topic can be found at _InterlockedCompareExchangePointer Intrinsic Functions.
Microsoft Specific**
Performs an atomic operation that stores the Exchange
address in the Destination
address if the Comparand
and the Destination
address are equal.
Syntax
void * _InterlockedCompareExchangePointer (
void * volatile * Destination,
void * Exchange,
void * Comparand
);
void * _InterlockedCompareExchangePointer_acq (
void * volatile * Destination,
void * Exchange,
void * Comparand
);
void * _InterlockedCompareExchangePointer_HLEAcquire (
void * volatile * Destination,
void * Exchange,
void * Comparand
);
void * _InterlockedCompareExchangePointer_HLERelease (
void * volatile * Destination,
void * Exchange,
void * Comparand
);
void * _InterlockedCompareExchangePointer_nf (
void * volatile * Destination,
void * Exchange,
void * Comparand
);
void * _InterlockedCompareExchangePointer_np (
void * volatile * Destination,
void * Exchange,
void * Comparand
);
long _InterlockedCompareExchangePointer_rel (
void * volatile * Destination,
void * Exchange,
void * Comparand
);
Parameters
[in, out] Destination
Pointer to a pointer to the destination value. The sign is ignored.
[in] Exchange
Exchange pointer. The sign is ignored.
[in] Comparand
Pointer to compare to destination. The sign is ignored.
Return Value
The return value is the initial value of the destination.
Requirements
Intrinsic | Architecture | Header |
---|---|---|
_InterlockedCompareExchangePointer |
x86, ARM, x64 | <intrin.h> |
_InterlockedCompareExchangePointer_acq , _InterlockedCompareExchangePointer_nf , _InterlockedCompareExchangePointer_rel |
ARM | <iiintrin.h> |
_InterlockedCompareExchangePointer_HLEAcquire , _InterlockedCompareExchangePointer_HLERelease |
x86, x64 | <immintrin.h> |
Remarks
_InterlockedCompareExchangePointer
performs an atomic comparison of the Destination
address with the Comparand
address. If the Destination
address is equal to the Comparand
address, the Exchange
address is stored in the address specified by Destination
. Otherwise, no operation is performed.
_InterlockedCompareExchangePointer
provides compiler intrinsic support for the Win32 Windows SDK _InterlockedCompareExchangePointer function.
For a example of how to use _InterlockedCompareExchangePointer
, see _InterlockedDecrement.
On ARM platforms, use the intrinsics with _acq
and _rel
suffixes if you need acquire and release semantics, such as at the beginning and end of a critical section. ARM intrinsics with an _nf
("no fence") suffix do not act as a memory barrier.
The intrinsics with an _np
("no prefetch") suffix prevent a possible prefetch operation from being inserted by the compiler.
On Intel platforms that support Hardware Lock Elision (HLE) instructions, the intrinsics with _HLEAcquire
and _HLERelease
suffixes include a hint to the processor that can accelerate performance by eliminating a lock write step in hardware. If these intrinsics are called on platforms that do not support HLE, the hint is ignored.
These routines are only available as intrinsics.