diff --git a/libcpu/aarch64/common/atomic_aarch64.c b/libcpu/aarch64/common/atomic_aarch64.c index 4b32951613..35dd2b0399 100644 --- a/libcpu/aarch64/common/atomic_aarch64.c +++ b/libcpu/aarch64/common/atomic_aarch64.c @@ -90,7 +90,6 @@ rt_atomic_t rt_hw_atomic_flag_test_and_set(volatile rt_atomic_t *ptr) rt_atomic_t rt_hw_atomic_compare_exchange_strong(volatile rt_atomic_t *ptr, rt_atomic_t *old, rt_atomic_t new) { rt_atomic_t tmp, oldval; - __asm__ volatile ( " prfm pstl1strm, %2\n" "1: ldxr %0, %2\n" @@ -99,10 +98,15 @@ rt_atomic_t rt_hw_atomic_compare_exchange_strong(volatile rt_atomic_t *ptr, rt_a " stlxr %w1, %4, %2\n" " cbnz %w1, 1b\n" " dmb ish\n" - "2:" + " mov %w1, #1\n" + " b 3f\n" + "2: str %0, [%5]\n" + " mov %w1, #0\n" + "3:" : "=&r" (oldval), "=&r" (tmp), "+Q" (*ptr) - : "Kr" (*old), "r" (new) + : "Kr" (*old), "r" (new), "r" (old) : "memory"); - return oldval == *old; + return tmp; } +