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