CAS returns the *old* value that was in the memory location before the operation took place. That is, if the return value when calling this function equals to 'oldVal', then the operation succeeded, otherwise it was ignored.
| 41 | // That is, if the return value when calling this function equals to 'oldVal', |
| 42 | // then the operation succeeded, otherwise it was ignored. |
| 43 | _EM_INLINE uint8_t emscripten_atomic_cas_u8(void /*uint8_t*/* _Nonnull addr, uint8_t oldVal, uint8_t newVal) { |
| 44 | uint8_t expected = oldVal; |
| 45 | __c11_atomic_compare_exchange_strong((_Atomic uint8_t*)addr, &expected, newVal, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST); |
| 46 | return expected; |
| 47 | } |
| 48 | _EM_INLINE uint16_t emscripten_atomic_cas_u16(void /*uint16_t*/* _Nonnull addr, uint16_t oldVal, uint16_t newVal) { |
| 49 | uint16_t expected = oldVal; |
| 50 | __c11_atomic_compare_exchange_strong((_Atomic uint16_t*)addr, &expected, newVal, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST); |