From f260c53d89b6e807be9e6a69a974fb0a135d7e77 Mon Sep 17 00:00:00 2001 From: Old-Ding Date: Mon, 29 Jun 2026 23:43:01 +0800 Subject: [PATCH] Fix RP2040 task lock acquire ordering Add an acquire fence after the RP2040 recursive lock fast path because spin_try_lock_unsafe() does not provide acquire ordering when the lock is acquired immediately. Signed-off-by: Old-Ding --- portable/ThirdParty/GCC/RP2040/include/portmacro.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/portable/ThirdParty/GCC/RP2040/include/portmacro.h b/portable/ThirdParty/GCC/RP2040/include/portmacro.h index d8173716eea..4e72bb07dc1 100644 --- a/portable/ThirdParty/GCC/RP2040/include/portmacro.h +++ b/portable/ThirdParty/GCC/RP2040/include/portmacro.h @@ -237,6 +237,11 @@ static inline void vPortRecursiveLock( BaseType_t xCoreID, } spin_lock_unsafe_blocking(pxSpinLock); } + else + { + /* spin_try_lock_unsafe() does not provide acquire ordering on the fast path. */ + __mem_fence_acquire(); + } configASSERT( ucRecursionCountByLock[ ulLockNum ] == 0 ); ucRecursionCountByLock[ ulLockNum ] = 1; ucOwnedByCore[ xCoreID ][ ulLockNum ] = 1;