Add a try version to acquire a spin lock.
Signed-off-by: Liam Girdwood liam.r.girdwood@linux.intel.com --- src/arch/xtensa/include/arch/spinlock.h | 18 ++++++++++++++++++ src/include/reef/lock.h | 4 ++++ 2 files changed, 22 insertions(+)
diff --git a/src/arch/xtensa/include/arch/spinlock.h b/src/arch/xtensa/include/arch/spinlock.h index acb1b8e..13bf4c1 100644 --- a/src/arch/xtensa/include/arch/spinlock.h +++ b/src/arch/xtensa/include/arch/spinlock.h @@ -62,6 +62,24 @@ static inline void arch_spin_lock(spinlock_t *lock) : "memory"); }
+static inline int arch_try_lock(spinlock_t *lock) +{ + uint32_t result; + + __asm__ __volatile__( + " movi %0, 0\n" + " wsr %0, scompare1\n" + " movi %0, 1\n" + " s32c1i %0, %1, 0\n" + : "=&a" (result) + : "a" (&lock->lock) + : "memory"); + + if (result) + return 0; /* lock failed */ + return 1; /* lock acquired */ +} + static inline void arch_spin_unlock(spinlock_t *lock) { uint32_t result; diff --git a/src/include/reef/lock.h b/src/include/reef/lock.h index eef2a3a..deb0fb7 100644 --- a/src/include/reef/lock.h +++ b/src/include/reef/lock.h @@ -149,6 +149,10 @@ extern uint32_t lock_dbg_user[DBG_LOCK_USERS]; spin_lock_dbg(); \ arch_spin_lock(lock);
+#define spin_try_lock(lock) \ + spin_lock_dbg(); \ + arch_try_lock(lock); + #define spin_unlock(lock) \ arch_spin_unlock(lock); \ spin_unlock_dbg();