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 | 体系结构 | Header |
|---|---|---|
| .- . | x86、ARM、x64、ARM64 | <intrin.h> |
_InterlockedExchange64 |
ARM、x64、ARM64 | <intrin.h> |
| ARM、ARM64 | <intrin.h> | |
| %> | x86、x64 | <immintrin.h> |
| %> | 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 专用