DotRecastNetSim/src/DotRecast.Core/RcAtomicLong.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-05-06 05:44:57 +03:00
public class RcAtomicLong
2023-03-16 19:48:49 +03:00
{
private long _location;
2023-05-06 05:44:57 +03:00
public RcAtomicLong() : this(0)
2023-03-16 19:48:49 +03:00
{
}
2023-05-06 05:44:57 +03:00
public RcAtomicLong(long location)
2023-03-16 19:48:49 +03:00
{
_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
}
}