| 1: | func @cmpxchg = <{TARGET: Type, VALUE: Type, IS_WEAK: Bool, SUCCESS_ORDER: @pthr.AtomicOrdering, FAILURE_ORDER: @pthr.AtomicOrdering}> (target: TARGET, expected: VALUE, desired: VALUE in) -> (loaded: VALUE, succeeded: Bool); |
Atomic compare-exchange. Trivially-compare the target against the expected value. If the are equal, store the desired value to target - this is considered a success. If the values differ, this is considered a failure, and no store is made.
TARGET: must be a non-optional pointer, and is a pointer to the type of value to store to
VALUE: must be the result of a dereference of TARGET. Must be integral, pointer, or Bool
IS_WEAK: If true, the operation is allowed to spuriously fail
SUCCESS_ORDER: Atomic memory order for the operation if it successfully stores the desired value
FAILURE_ORDER: Atomic memory order for the operation if it fails to store the desired value - cannot be @pthr.AtomicOrdering.RELEASE or @pthr.AtomicOrdering.ACQ_REL
target: target to operate read-modify-write operation on
expected: value that is expected - only stores the desired value if the target value is expected
desired: value to store if the value is expected
loaded: value loaded at target
succeeded: is true if the value was successfully stored
If calling from a loop, IS_WEAK should usually be true as it can result in better performance on the platforms that support weak compare-exchange. On platforms that do not support weak compare-exchange, setting IS_WEAK to true has no effect.
(TODO)
| @atomicLoad | Atomically load a value |
| @atomicStore | Atomically store a value |
| @atomicRMW | Atomic read-modify-write |