Skip to main content

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​

TypeDescription
boolThe 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​

NameTypeDescription
oldboolThe expected current boolean value for the comparison.
newboolThe new boolean value to set if the comparison succeeds.

Returns​

TypeDescription
boolTrue 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​

NameTypeDescription
newboolThe 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​

NameTypeDescription
newboolThe new boolean value to set.

Returns​

TypeDescription
boolThe 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​

TypeDescription
boolThe new boolean value after toggling.