分享方式:


_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 所指的初始值。

需求

內建 架構 標題
_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 (「無柵欄」) 尾碼的內建函式不會作為記憶體屏障。

在支援 Hardware Lock Elision (HLE) 指令的 Intel 平台上,搭配 _HLEAcquire_HLERelease 字尾的內建函式會包含對處理器的提示,提示其可以藉由消除硬體中鎖定寫入 (lock write) 的階段以加速效能。 如果在不支援 HLE 的平台上呼叫這些內建函式,會忽略該提示。

這些常式僅以內建函式的形式供您使用。

範例

如需如何使用 _InterlockedExchange 的範例,請參閱 _InterlockedDecrement

END Microsoft 特定的

另請參閱

編譯器內建函式
關鍵字
與 x86 編譯器衝突