Udostępnij za pośrednictwem


_InterlockedCompareExchangePointer Intrinsic Functions

Microsoft Specific

Provides compiler intrinsic support for the Win32 Windows SDK _InterlockedCompareExchangePointer function.

void * _InterlockedCompareExchangePointer (
   void * volatile * Destination,
   void * Exchange,
   void * Comperand
);
void * _InterlockedCompareExchangePointer_acq (
   void * volatile * Destination,
   void * Exchange,
   void * Comperand
);
long _InterlockedCompareExchangePointer_rel (
   void * volatile * Destination,
   void * Exchange,
   void * Comperand
);

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] Comperand
    Pointer to compare to destination. The sign is ignored.

Return Value

The return value is the initial value of the destination.

Requirements

Intrinsic

Architecture

_InterlockedCompareExchangePointer

x86, IPF, x64

_InterlockedCompareExchangePointer_acq

IPF

_InterlockedCompareExchangePointer_rel

IPF

Header file <intrin.h>

Remarks

Note that to generate the intrinsic expansion, you need to use /Oi. /Oi is implied with /O2.

To declare one of the interlocked functions for use as an intrinsic, the function must be declared with the leading underscore and the new function must appear in a #pragma intrinsic statement. For convenience, the intrinsic versions of the functions can be declared in a #define statement to appear in the source code without the leading underscore.

_InterlockedCompareExchangePointer performs an atomic comparison of the Destination address with the Comperand address. If the Destination address is equal to the Comperand address, the Exchange address is stored in the address specified by Destination. Otherwise, no operation is performed.

For a example of how to use _InterlockedCompareExchangePointer, see _InterlockedDecrement.

The _InterlockedCompareExchangePointer_acq intrinsic function is the same as the corresponding function without the acq suffix except that the operation is performed with acquire semantics, which is useful when entering a critical section.

The _InterlockedCompareExchangePointer_rel intrinsic function are the same as the corresponding function without the rel suffix except that the operation is performed with release semantics, which is useful when leaving a critical section.

These functions behave as read-write memory barriers. For more information, see _ReadWriteBarrier.

These routines are only available as intrinsics.

See Also

Reference

Compiler Intrinsics

C++ Keywords