This is an automated email from the ASF dual-hosted git repository. xiaoxiang781216 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit e0aea7043c463f67a735f0ad3965c43b0b518769 Author: ouyangxiangzhen <[email protected]> AuthorDate: Fri Feb 6 11:37:27 2026 +0800 spinlock: Add compiler_assume for rspinlock. This commit added compiler_assume hint for rspinlock to do more aggresive optimization. Assisted-By: mimo-v2.6-pro Signed-off-by: ouyangxiangzhen <[email protected]> --- include/nuttx/spinlock.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/include/nuttx/spinlock.h b/include/nuttx/spinlock.h index ab43073490c..ac91620eed8 100644 --- a/include/nuttx/spinlock.h +++ b/include/nuttx/spinlock.h @@ -565,6 +565,13 @@ void rspin_lock(FAR rspinlock_t *lock) old_val = 0u; } while (!atomic_cmpxchg_acquire(&lock->val, &old_val, new_val)); + + /* The local value shares the same memory location with the + * global atomic value. So if the atomic operation success, + * the local value should also change to the new_val. + */ + + compiler_assume(lock->local_val == new_val); } } @@ -637,6 +644,18 @@ static inline_function bool rspin_trylock(FAR rspinlock_t *lock) ret = atomic_cmpxchg_acquire(&lock->val, &old_val, RSPINLOCK_VALUE(owner, 1u)); + + /* Mark locked when the lock is successfully acquired. */ + + if (ret) + { + /* The local value shares the same memory location with the + * global atomic value. So if the atomic operation success, + * the local value should also change to the new_val. + */ + + compiler_assume(lock->local_val == RSPINLOCK_VALUE(owner, 1u)); + } } return ret;
