interlockedhelper.cs
来自「破解的飞信源代码」· CS 代码 · 共 48 行
CS
48 行
namespace NCindy.Util
{
using System;
using System.Runtime.InteropServices;
using System.Threading;
public static class InterlockedHelper
{
public static int And(ref int target, int with)
{
int comparand;
int num2 = target;
do
{
comparand = num2;
num2 = Interlocked.CompareExchange(ref target, comparand & with, comparand);
}
while (comparand != num2);
return num2;
}
public static bool CompareAndExchange(ref int value, int ifThisEqualsToValue, int thenExchangeValueWithThis)
{
return (Interlocked.CompareExchange(ref value, thenExchangeValueWithThis, ifThisEqualsToValue) == ifThisEqualsToValue);
}
public static bool CompareAndExchange(ref int value, int ifThisEqualsToValue, int thenExchangeValueWithThis, out int originalValue)
{
originalValue = Interlocked.CompareExchange(ref value, thenExchangeValueWithThis, ifThisEqualsToValue);
return (originalValue == ifThisEqualsToValue);
}
public static int Or(ref int target, int with)
{
int comparand;
int num2 = target;
do
{
comparand = num2;
num2 = Interlocked.CompareExchange(ref target, comparand | with, comparand);
}
while (comparand != num2);
return num2;
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?