Struct UnsafeAtomicCounter64
A 64-bit atomic counter.
Namespace: Unity.Collections.LowLevel.Unsafe
Assembly: Unity.Collections.dll
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 |
---|---|
long* | The long that is modified by this counter. |
Methods
Add(long)
Atomically adds a value to this counter.
Declaration
public long Add(long value)
Parameters
Type | Name | Description |
---|---|---|
long | value | The value to add. |
Returns
Type | Description |
---|---|
long | The original value before the add. |
AddSat(long, long)
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 = 9223372036854775807)
Parameters
Type | Name | Description |
---|---|---|
long | value | The value to add to this counter. |
long | max | The maximum which the result will not be greater than. |
Returns
Type | Description |
---|---|
long | The original value before the add. |
Reset(long)
Non-atomically sets this counter to a value.
Declaration
public void Reset(long value = 0)
Parameters
Type | Name | Description |
---|---|---|
long | value | The value to set. Defaults to 0 |
Sub(long)
Atomically subtracts a value from this counter.
Declaration
public long Sub(long value)
Parameters
Type | Name | Description |
---|---|---|
long | value | The value to subtract. |
Returns
Type | Description |
---|---|
long | The original value before the subtract. |
SubSat(long, long)
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 = -9223372036854775808)
Parameters
Type | Name | Description |
---|---|---|
long | value | The value to subtract from this counter. |
long | min | The minimum which the result will not be less than. |
Returns
Type | Description |
---|---|
long | The original value before the subtract. |