Struct UnsafeAtomicCounter64
A 64-bit atomic counter.
Namespace: Unity.Collections.LowLevel.Unsafe
Syntax
public struct UnsafeAtomicCounter64
Remarks
Rather than have its own long, a counter points to a long. This arrangement lets counters in different jobs share reference to the same underlying long.
Constructors
UnsafeAtomicCounter64(Void*)
Initializes and returns an instance of UnsafeAtomicCounter64.
Declaration
public UnsafeAtomicCounter64(void *ptr)
Parameters
Type | Name | Description |
---|---|---|
Void* | ptr | A pointer to the long to be modified by this counter. |
Fields
Counter
The long that is modified by this counter.
Declaration
public long *Counter
Field Value
Type | Description |
---|---|
Int64* | The long that is modified by this counter. |
Methods
Add(Int64)
Atomically adds a value to this counter.
Declaration
public long Add(long value)
Parameters
Type | Name | Description |
---|---|---|
Int64 | value | The value to add. |
Returns
Type | Description |
---|---|
Int64 | The original value before the add. |
AddSat(Int64, Int64)
Atomically adds a value to this counter. The result will not be greater than a maximum value.
Declaration
public long AddSat(long value, long max = 9223372036854775807L)
Parameters
Type | Name | Description |
---|---|---|
Int64 | value | The value to add to this counter. |
Int64 | max | The maximum which the result will not be greater than. |
Returns
Type | Description |
---|---|
Int64 | The original value before the add. |
Reset(Int64)
Non-atomically sets this counter to a value.
Declaration
public void Reset(long value = 0L)
Parameters
Type | Name | Description |
---|---|---|
Int64 | value | The value to set. Defaults to 0 |
Sub(Int64)
Atomically subtracts a value from this counter.
Declaration
public long Sub(long value)
Parameters
Type | Name | Description |
---|---|---|
Int64 | value | The value to subtract. |
Returns
Type | Description |
---|---|
Int64 | The original value before the subtract. |
SubSat(Int64, Int64)
Atomically subtracts a value from this counter. The result will not be less than a minimum value.
Declaration
public long SubSat(long value, long min = -9223372036854775808L)
Parameters
Type | Name | Description |
---|---|---|
Int64 | value | The value to subtract from this counter. |
Int64 | min | The minimum which the result will not be less than. |
Returns
Type | Description |
---|---|
Int64 | The original value before the subtract. |