次の方法で共有


_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 に設定し、変数の前の値を返します。

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") のサフィックスの付いたものは、メモリ バリアとして機能しません。

Hardware Lock Elision (HLE) 命令をサポートする Intel プラットフォームでは、_HLEAcquire および _HLERelease サフィックスの付いた組み込みにプロセッサへのヒントが含まれています。このヒントによりハードウェアでのロック書き込み手順を省くことで、パフォーマンスを向上させることができます。 HLE をサポートしていないプラットフォームでこれらの組み込みが呼び出された場合、ヒントは無視されます。

これらのルーチンは、組み込みとしてのみ使用できます。

_InterlockedExchange の使用例については、_InterlockedDecrement に関するページを参照してください。

Microsoft 固有の仕様はここまで

関連項目

コンパイラの組み込み
キーワード
x86 コンパイラとの競合