From 0b30742c8035b80637b5a5b1d66c274337940ff6 Mon Sep 17 00:00:00 2001 From: Kevin Bracey Date: Thu, 3 Dec 2020 16:23:33 +0200 Subject: [PATCH] Add missing retry to atomic exchange Atomic exchange implementation forgot to do the retry if the exclusive store failed. --- platform/include/platform/internal/mbed_atomic_impl.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/platform/include/platform/internal/mbed_atomic_impl.h b/platform/include/platform/internal/mbed_atomic_impl.h index b29a0aec41..cc80ce8dc7 100644 --- a/platform/include/platform/internal/mbed_atomic_impl.h +++ b/platform/include/platform/internal/mbed_atomic_impl.h @@ -346,7 +346,9 @@ inline T core_util_atomic_exchange_##fn_suffix(volatile T *valuePtr, T newValue) T oldValue; \ uint32_t fail; \ MBED_BARRIER(); \ - DO_MBED_LOCKFREE_EXCHG_ASM(M); \ + do { \ + DO_MBED_LOCKFREE_EXCHG_ASM(M); \ + } while (fail); \ MBED_BARRIER(); \ return oldValue; \ } \ @@ -357,7 +359,9 @@ MBED_FORCEINLINE T core_util_atomic_exchange_explicit_##fn_suffix( T oldValue; \ uint32_t fail; \ MBED_RELEASE_BARRIER(order); \ - DO_MBED_LOCKFREE_EXCHG_ASM(M); \ + do { \ + DO_MBED_LOCKFREE_EXCHG_ASM(M); \ + } while (fail); \ MBED_ACQUIRE_BARRIER(order); \ return oldValue; \ }