Added 32 and 64 bit atomic exchange operations in relaxed memory ordering. These can be used e.g. to initialize a counter while counting.
Signed-off-by: Petri Savolainen <petri.savolai...@nokia.com> --- include/odp/api/atomic.h | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/include/odp/api/atomic.h b/include/odp/api/atomic.h index 1abaaf3..8626495 100644 --- a/include/odp/api/atomic.h +++ b/include/odp/api/atomic.h @@ -198,6 +198,19 @@ void odp_atomic_min_u32(odp_atomic_u32_t *atom, uint32_t new_min); int odp_atomic_cas_u32(odp_atomic_u32_t *atom, uint32_t *old_val, uint32_t new_val); +/** + * Exchange value of atomic uint32 variable + * + * Atomically replaces the value of atomic variable with the new value. Returns + * the old value. + * + * @param atom Pointer to atomic variable + * @param new_val New value of the atomic variable + * + * @return Value of the variable before the operation + */ +uint32_t odp_atomic_xchg_u32(odp_atomic_u32_t *atom, uint32_t new_val); + /* * 64-bit operations in RELAXED memory ordering * -------------------------------------------- @@ -336,6 +349,19 @@ void odp_atomic_min_u64(odp_atomic_u64_t *atom, uint64_t new_min); int odp_atomic_cas_u64(odp_atomic_u64_t *atom, uint64_t *old_val, uint64_t new_val); +/** + * Exchange value of atomic uint64 variable + * + * Atomically replaces the value of atomic variable with the new value. Returns + * the old value. + * + * @param atom Pointer to atomic variable + * @param new_val New value of the atomic variable + * + * @return Value of the variable before the operation + */ +uint64_t odp_atomic_xchg_u64(odp_atomic_u64_t *atom, uint64_t new_val); + /* * 32-bit operations in non-RELAXED memory ordering * ------------------------------------------------ @@ -556,6 +582,7 @@ typedef union odp_atomic_op_t { uint32_t min : 1; /**< Atomic minimum */ uint32_t max : 1; /**< Atomic maximum */ uint32_t cas : 1; /**< Atomic compare and swap */ + uint32_t xchg : 1; /**< Atomic exchange */ } op; /** All bits of the bit field structure. -- 2.6.3 _______________________________________________ lng-odp mailing list lng-odp@lists.linaro.org https://lists.linaro.org/mailman/listinfo/lng-odp