DotRecastNetSim/src/DotRecast.Core/AtomicLong.cs

53 lines
1.1 KiB
C#
Raw Normal View History

2023-03-14 08:02:43 +03:00
using System.Threading;
2023-03-16 19:09:10 +03:00
namespace DotRecast.Core
{
2023-03-16 19:48:49 +03:00
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);
}
2023-03-14 08:02:43 +03:00
}
}