DotRecastNetSim/src/DotRecast.Core/AtomicLong.cs

52 lines
1004 B
C#
Raw Normal View History

2023-03-14 08:02:43 +03:00
using System.Threading;
namespace DotRecast.Core;
public class AtomicLong
{
private long _location;
public AtomicLong() : this(0)
{
}
public AtomicLong(long location)
{
_location = location;
}
public long IncrementAndGet()
{
return Interlocked.Increment(ref _location);
}
public long DecrementAndGet()
{
return Interlocked.Decrement(ref _location);
}
public long Read()
{
return Interlocked.Read(ref _location);
}
public long Exchange(long exchange)
{
return Interlocked.Exchange(ref _location, exchange);
}
public long Decrease(long value)
{
return Interlocked.Add(ref _location, -value);
}
public long CompareExchange(long value, long comparand)
{
return Interlocked.CompareExchange(ref _location, value, comparand);
}
public long AddAndGet(long value)
{
return Interlocked.Add(ref _location, value);
}
}