Mojo struct
Atomic
Represents a value with atomic operations.
The class provides atomic add
and sub
methods for mutating the value.
Parameters
- type (
DType
): DType of the value.
Fields
- value (
SIMD[type, 1]
): The atomic value.
Implemented traits
AnyType
Methods
__init__
__init__(out self, value: SIMD[type, 1])
Constructs a new atomic value.
Args:
- value (
SIMD[type, 1]
): Initial value represented asScalar[type]
type.
__iadd__
__iadd__(inout self, rhs: SIMD[type, 1])
Performs atomic in-place add.
Atomically replaces the current value with the result of arithmetic addition of the value and arg. That is, it performs atomic post-increment. The operation is a read-modify-write operation. Memory is affected according to the value of order which is sequentially consistent.
Args:
- rhs (
SIMD[type, 1]
): Value to add.
__isub__
__isub__(inout self, rhs: SIMD[type, 1])
Performs atomic in-place sub.
Atomically replaces the current value with the result of arithmetic subtraction of the value and arg. That is, it performs atomic post-decrement. The operation is a read-modify-write operation. Memory is affected according to the value of order which is sequentially consistent.
Args:
- rhs (
SIMD[type, 1]
): Value to subtract.
load
load(inout self) -> SIMD[type, 1]
Loads the current value from the atomic.
Returns:
The current value of the atomic.
fetch_add
fetch_add(inout self, rhs: SIMD[type, 1]) -> SIMD[type, 1]
Performs atomic in-place add.
Atomically replaces the current value with the result of arithmetic addition of the value and arg. That is, it performs atomic post-increment. The operation is a read-modify-write operation. Memory is affected according to the value of order which is sequentially consistent.
Args:
- rhs (
SIMD[type, 1]
): Value to add.
Returns:
The original value before addition.
fetch_sub
fetch_sub(inout self, rhs: SIMD[type, 1]) -> SIMD[type, 1]
Performs atomic in-place sub.
Atomically replaces the current value with the result of arithmetic subtraction of the value and arg. That is, it performs atomic post-decrement. The operation is a read-modify-write operation. Memory is affected according to the value of order which is sequentially consistent.
Args:
- rhs (
SIMD[type, 1]
): Value to subtract.
Returns:
The original value before subtraction.
compare_exchange_weak
compare_exchange_weak(inout self, inout expected: SIMD[type, 1], desired: SIMD[type, 1]) -> Bool
Atomically compares the self value with that of the expected value. If the values are equal, then the self value is replaced with the desired value and True is returned. Otherwise, False is returned the the expected value is rewritten with the self value.
Args:
- expected (
SIMD[type, 1]
): The expected value. - desired (
SIMD[type, 1]
): The desired value.
Returns:
True if self == expected and False otherwise.
max
static max(ptr: UnsafePointer[SIMD[type, 1], address_space, alignment, origin], rhs: SIMD[type, 1])
Performs atomic in-place max on the pointer.
Atomically replaces the current value pointer to by ptr
by the result
of max of the value and arg. The operation is a read-modify-write
operation. The operation is a read-modify-write operation perform
according to sequential consistency semantics.
Constraints:
The input type must be either integral or floating-point type.
Args:
- ptr (
UnsafePointer[SIMD[type, 1], address_space, alignment, origin]
): The source pointer. - rhs (
SIMD[type, 1]
): Value to max.
max(inout self, rhs: SIMD[type, 1])
Performs atomic in-place max.
Atomically replaces the current value with the result of max of the value and arg. The operation is a read-modify-write operation perform according to sequential consistency semantics.
Constraints:
The input type must be either integral or floating-point type.
Args:
- rhs (
SIMD[type, 1]
): Value to max.
min
static min(ptr: UnsafePointer[SIMD[type, 1], address_space, alignment, origin], rhs: SIMD[type, 1])
Performs atomic in-place min on the pointer.
Atomically replaces the current value pointer to by ptr
by the result
of min of the value and arg. The operation is a read-modify-write
operation. The operation is a read-modify-write operation perform
according to sequential consistency semantics.
Constraints:
The input type must be either integral or floating-point type.
Args:
- ptr (
UnsafePointer[SIMD[type, 1], address_space, alignment, origin]
): The source pointer. - rhs (
SIMD[type, 1]
): Value to min.
min(inout self, rhs: SIMD[type, 1])
Performs atomic in-place min.
Atomically replaces the current value with the result of min of the value and arg. The operation is a read-modify-write operation. The operation is a read-modify-write operation perform according to sequential consistency semantics.
Constraints:
The input type must be either integral or floating-point type.
Args:
- rhs (
SIMD[type, 1]
): Value to min.
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!