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