_InterlockedAnd內建函式
Microsoft 特定的
用來執行多個執行緒所共用的變數上,不可部分完成的位元 AND 運算。
語法
long _InterlockedAnd(
long volatile * value,
long mask
);
long _InterlockedAnd_acq(
long volatile * value,
long mask
);
long _InterlockedAnd_HLEAcquire(
long volatile * value,
long mask
);
long _InterlockedAnd_HLERelease(
long volatile * value,
long mask
);
long _InterlockedAnd_nf(
long volatile * value,
long mask
);
long _InterlockedAnd_np(
long volatile * value,
long mask
);
long _InterlockedAnd_rel(
long volatile * value,
long mask
);
char _InterlockedAnd8(
char volatile * value,
char mask
);
char _InterlockedAnd8_acq(
char volatile * value,
char mask
);
char _InterlockedAnd8_nf(
char volatile * value,
char mask
);
char _InterlockedAnd8_np(
char volatile * value,
char mask
);
char _InterlockedAnd8_rel(
char volatile * value,
char mask
);
short _InterlockedAnd16(
short volatile * value,
short mask
);
short _InterlockedAnd16_acq(
short volatile * value,
short mask
);
short _InterlockedAnd16_nf(
short volatile * value,
short mask
);
short _InterlockedAnd16_np(
short volatile * value,
short mask
);
short _InterlockedAnd16_rel(
short volatile * value,
short mask
);
__int64 _InterlockedAnd64(
__int64 volatile* value,
__int64 mask
);
__int64 _InterlockedAnd64_acq(
__int64 volatile* value,
__int64 mask
);
__int64 _InterlockedAnd64_HLEAcquire(
__int64 volatile* value,
__int64 mask
);
__int64 _InterlockedAnd64_HLERelease(
__int64 volatile* value,
__int64 mask
);
__int64 _InterlockedAnd64_nf(
__int64 volatile* value,
__int64 mask
);
__int64 _InterlockedAnd64_np(
__int64 volatile* value,
__int64 mask
);
__int64 _InterlockedAnd64_rel(
__int64 volatile* value,
__int64 mask
);
參數
value
[in, out]要由結果取代之第一個運算元的指標。
面具
[in]第二個運算元。
傳回值
第一個運算元的原始值。
需求
內建 | 架構 | 標題 |
---|---|---|
_InterlockedAnd , _InterlockedAnd8 , _InterlockedAnd16 |
x86、ARM、x64、ARM64 | <intrin.h> |
_InterlockedAnd64 |
ARM、x64、ARM64 | <intrin.h> |
_InterlockedAnd_acq , _InterlockedAnd_nf , _InterlockedAnd_rel , _InterlockedAnd8_acq , _InterlockedAnd8_nf , _InterlockedAnd8_rel , _InterlockedAnd16_acq , _InterlockedAnd16_nf , _InterlockedAnd16_rel , _InterlockedAnd64_acq , _InterlockedAnd64_nf , _InterlockedAnd64_rel |
ARM、ARM64 | <intrin.h> |
_InterlockedAnd_np , _InterlockedAnd8_np , _InterlockedAnd16_np , _InterlockedAnd64_np |
x64 | <intrin.h> |
_InterlockedAnd_HLEAcquire , _InterlockedAnd_HLERelease , _InterlockedAnd64_HLEAcquire , _InterlockedAnd64_HLERelease |
x86、x64 | <immintrin.h> |
備註
每個函式名稱的數字會指定引數的位元大小。
在 ARM 和 ARM64 平臺上,使用內建和 _acq
_rel
尾碼取得和發行語意,例如在重要區段的開頭和結尾。 搭配 _nf
(「無範圍」) 字尾的內建函式,不會當做記憶體屏障。
搭配 _np
(「不預先擷取」) 字尾使用內建函式,可避免編譯器插入可能的預先提取作業。
在支援 Hardware Lock Elision (HLE) 指令的 Intel 平台上,搭配 _HLEAcquire
和 _HLERelease
字尾的內建函式會包含對處理器的提示,提示其可以藉由消除硬體中鎖定寫入 (lock write) 的階段以加速效能。 如果在不支援 HLE 的平台上呼叫這些內建函式,會忽略該提示。
範例
// InterlockedAnd.cpp
// Compile with: /Oi
#include <stdio.h>
#include <intrin.h>
#pragma intrinsic(_InterlockedAnd)
int main()
{
long data1 = 0xFF00FF00;
long data2 = 0x00FFFF00;
long retval;
retval = _InterlockedAnd(&data1, data2);
printf_s("0x%x 0x%x 0x%x", data1, data2, retval);
}
0xff00 0xffff00 0xff00ff00
END Microsoft 特定的
另請參閱
意見反映
https://aka.ms/ContentUserFeedback。
即將推出:我們會在 2024 年淘汰 GitHub 問題,並以全新的意見反應系統取代並作為內容意見反應的渠道。 如需更多資訊,請參閱:提交及檢視以下的意見反映: