Bool
This class represents an atomic Boolean. It stores the boolean value as an unsigned 32-bit integer internally to leverage atomic functions available in Go.
Methods
Load()
@classmethod
def Load() - > bool
Fetches the current boolean value stored in the atomic boolean. Callers use this to retrieve the current state without modification.
Returns
| Type | Description |
|---|---|
bool | The current boolean value. |
CompareAndSwap()
@classmethod
def CompareAndSwap(
old: bool,
new: bool
) - > bool
Atomically compares the current boolean value with 'old' and, if they are equal, replaces the current value with 'new'. This is used for conditional updates, ensuring the value is changed only if it matches an expected state.
Parameters
| Name | Type | Description |
|---|---|---|
| old | bool | The expected current boolean value for the comparison. |
| new | bool | The new boolean value to set if the comparison succeeds. |
Returns
| Type | Description |
|---|---|
bool | True if the swap occurred (i.e., the old value matched the current value), false otherwise. |
Store()
@classmethod
def Store(
new: bool
)
Atomically sets the boolean to the 'new' value. Callers use this to unconditionally update the boolean's state.
Parameters
| Name | Type | Description |
|---|---|---|
| new | bool | The new boolean value to store. |
Swap()
@classmethod
def Swap(
new: bool
) - > bool
Atomically sets the boolean to the 'new' value and returns the old value. Callers use this to update the state and simultaneously retrieve the previous state.
Parameters
| Name | Type | Description |
|---|---|---|
| new | bool | The new boolean value to set. |
Returns
| Type | Description |
|---|---|
bool | The boolean value that was present before the swap. |
Toggle()
@classmethod
def Toggle() - > bool
Atomically flips the current boolean value (true becomes false, false becomes true). Callers use this to invert the boolean's state.
Returns
| Type | Description |
|---|---|
bool | The new boolean value after toggling. |