mirror of
https://gitee.com/jisol/jisol-game/
synced 2025-06-26 19:34:47 +00:00
66 lines
1.7 KiB
C#
66 lines
1.7 KiB
C#
namespace JNGame.Util.NoThread
|
|
{
|
|
public class Interlocked
|
|
{
|
|
public static long Read(ref long location)
|
|
{
|
|
return location;
|
|
}
|
|
public static int Increment(ref int location)
|
|
{
|
|
return location += 1;
|
|
}
|
|
public static long Increment(ref long location)
|
|
{
|
|
return location += 1;
|
|
}
|
|
public static int Decrement(ref int location)
|
|
{
|
|
return location -= 1;
|
|
}
|
|
public static long Decrement(ref long location)
|
|
{
|
|
return location -= 1;
|
|
}
|
|
public static int Exchange(ref int location, int value)
|
|
{
|
|
int temp = location;
|
|
return location = value;
|
|
}
|
|
public static long Exchange(ref long location, long value)
|
|
{
|
|
long temp = location;
|
|
return location = value;
|
|
}
|
|
public static int Add(ref int location, int value)
|
|
{
|
|
return location += value;
|
|
}
|
|
public static long Add(ref long location, long value)
|
|
{
|
|
return location += value;
|
|
}
|
|
public static int CompareExchange(ref int location, int value, int comparand)
|
|
{
|
|
if (location == comparand)
|
|
{
|
|
return location = value;
|
|
}
|
|
else
|
|
{
|
|
return location;
|
|
}
|
|
}
|
|
public static long CompareExchange(ref long location, long value, long comparand)
|
|
{
|
|
if (location == comparand)
|
|
{
|
|
return location = value;
|
|
}
|
|
else
|
|
{
|
|
return location;
|
|
}
|
|
}
|
|
}
|
|
} |