_InterlockedExchange 内部函数

Microsoft 专用

生成原子指令以设置指定的值。

语法

long _InterlockedExchange(
   long volatile * Target,
   long Value
);
long _InterlockedExchange_acq(
   long volatile * Target,
   long Value
);
long _InterlockedExchange_HLEAcquire(
   long volatile * Target,
   long Value
);
long _InterlockedExchange_HLERelease(
   long volatile * Target,
   long Value
);
long _InterlockedExchange_nf(
   long volatile * Target,
   long Value
);
long _InterlockedExchange_rel(
   long volatile * Target,
   long Value
);
char _InterlockedExchange8(
   char volatile * Target,
   char Value
);
char _InterlockedExchange8_acq(
   char volatile * Target,
   char Value
);
char _InterlockedExchange8_nf(
   char volatile * Target,
   char Value
);
char _InterlockedExchange8_rel(
   char volatile * Target,
   char Value
);
short _InterlockedExchange16(
   short volatile * Target,
   short Value
);
short _InterlockedExchange16_acq(
   short volatile * Target,
   short Value
);
short _InterlockedExchange16_nf(
   short volatile * Target,
   short Value
);
short _InterlockedExchange16_rel(
   short volatile * Target,
   short Value
);
__int64 _InterlockedExchange64(
   __int64 volatile * Target,
   __int64 Value
);
__int64 _InterlockedExchange64_acq(
   __int64 volatile * Target,
   __int64 Value
);
__int64 _InterlockedExchange64_HLEAcquire(
   __int64 volatile * Target,
   __int64 Value
);
__int64 _InterlockedExchange64_HLERelease(
   __int64 volatile * Target,
   __int64 Value
);
__int64 _InterlockedExchange64_nf(
   __int64 volatile * Target,
   __int64 Value
);
__int64 _InterlockedExchange64_rel(
   __int64 volatile * Target,
   __int64 Value
);

参数

Target
[in, out] 指向要交换的值。 此函数会将此变量设置为 Value 并返回其之前的值。


[in] 与 Target 指向的值交换的值。

返回值

返回由 Target 指向的初始值。

要求

Intrinsic 体系结构 标头
_InterlockedExchange, _InterlockedExchange8, _InterlockedExchange16 x86、ARM、x64、ARM64 <intrin.h>
_InterlockedExchange64 ARM、x64、ARM64 <intrin.h>
_InterlockedExchange_acq_InterlockedExchange_nf_InterlockedExchange_rel_InterlockedExchange8_acq_InterlockedExchange8_nf_InterlockedExchange8_rel_InterlockedExchange16_acq_InterlockedExchange16_nf_InterlockedExchange16_rel_InterlockedExchange64_acq_InterlockedExchange64_nf_InterlockedExchange64_rel ARM、ARM64 <intrin.h>
_InterlockedExchange_HLEAcquire_InterlockedExchange_HLERelease x86、x64 <immintrin.h>
_InterlockedExchange64_HLEAcquire_InterlockedExchange64_HLERelease x64 <immintrin.h>

备注

_InterlockedExchange 为 Win32 Windows SDK InterlockedExchange 函数提供编译器内部支持。

_InterlockedExchange 存在几种变体,这些变体根据其涉及的数据类型和是否使用特定于处理器获取或发布语义而有所不同。

_InterlockedExchange 函数对 32 位整数值操作时,_InterlockedExchange8 对 8 位整数值操作,_InterlockedExchange16 对 16 位整数值操作且 _InterlockedExchange64 对 64 位整数值操作。

在 ARM 平台上,可以使用带 _acq_rel 后缀的内部函数获取和发布语义,例如在临界区的起始位置。 带 _nf(“no fence”)后缀的内部函数不充当内存屏障。

在支持硬件锁省略 (HLE) 指令的 Intel 平台,带 _HLEAcquire_HLERelease 后缀的内部函数包括一个发送到处理器的提示,可以通过消除硬件中的锁写步骤来提升速度。 如果在不支持 HLE 的平台上调用这些函数,则忽略此提示。

这些例程只能用作内部函数。

示例

有关如何使用 _InterlockedExchange 的示例,请参阅 _InterlockedDecrement

结束 Microsoft 专用

另请参阅

编译器内部函数
关键字
与 x86 编译器冲突