On x86, LOCK DEC is cheaper than LOCK CMPXCHG and doesn't require a
retry loop around it.
Signed-off-by: Jan Beulich <jbeulich@suse.com>
Reviewed-by: Tim Deegan <tim@xen.org>
Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
return 1;
}
-void _read_unlock(rwlock_t *lock)
-{
- uint32_t x, y;
+#ifndef _raw_read_unlock
+# define _raw_read_unlock(l) do { \
+ uint32_t x = (l)->lock, y; \
+ while ( (y = cmpxchg(&(l)->lock, x, x - 1)) != x ) \
+ x = y; \
+} while (0)
+#endif
+inline void _read_unlock(rwlock_t *lock)
+{
preempt_enable();
- x = lock->lock;
- while ( (y = cmpxchg(&lock->lock, x, x-1)) != x )
- x = y;
+ _raw_read_unlock(lock);
}
void _read_unlock_irq(rwlock_t *lock)
return (oldval > 0);
}
+#define _raw_read_unlock(l) \
+ asm volatile ( "lock; dec%z0 %0" : "+m" ((l)->lock) :: "memory" )
+
#endif /* __ASM_SPINLOCK_H */