Some cleanup in spinlock.h - Expand macros that are only called once into caller for cleaner code. - Turn all spinlock macros into inlines - Turn all __asm__ __volatile__s into asm volatile The result is much more readable, but shouldn't generate any Signed-off-by: Andi Kleen different code. --- include/asm-x86_64/rwlock.h | 14 -------------- include/asm-x86_64/spinlock.h | 23 +++++++++++++++++++---- 2 files changed, 19 insertions(+), 18 deletions(-) Index: linux/include/asm-x86_64/rwlock.h =================================================================== --- linux.orig/include/asm-x86_64/rwlock.h +++ linux/include/asm-x86_64/rwlock.h @@ -20,18 +20,4 @@ #define RW_LOCK_BIAS 0x01000000 -#define __build_read_lock(rw) \ - asm volatile(LOCK_PREFIX "subl $1,(%0)\n\t" \ - "jns 1f\n" \ - "call __read_lock_failed\n" \ - "1:\n" \ - ::"D" (rw), "i" (RW_LOCK_BIAS) : "memory") - -#define __build_write_lock(rw) \ - asm volatile(LOCK_PREFIX "subl %1,(%0)\n\t" \ - "jz 1f\n" \ - "\tcall __write_lock_failed\n\t" \ - "1:\n" \ - ::"D" (rw), "i" (RW_LOCK_BIAS) : "memory") - #endif Index: linux/include/asm-x86_64/spinlock.h =================================================================== --- linux.orig/include/asm-x86_64/spinlock.h +++ linux/include/asm-x86_64/spinlock.h @@ -80,17 +80,32 @@ static inline void __raw_spin_unlock(raw * with the high bit (sign) being the "contended" bit. */ -#define __raw_read_can_lock(x) ((int)(x)->lock > 0) -#define __raw_write_can_lock(x) ((x)->lock == RW_LOCK_BIAS) +static inline int __raw_read_can_lock(raw_rwlock_t *rw) +{ + return (int)rw->lock > 0; +} + +static inline int __raw_write_can_lock(raw_rwlock_t *rw) +{ + return rw->lock == RW_LOCK_BIAS; +} static inline void __raw_read_lock(raw_rwlock_t *rw) { - __build_read_lock(rw); + asm volatile(LOCK_PREFIX "subl $1,(%0)\n\t" + "jns 1f\n" + "call __read_lock_failed\n" + "1:\n" + ::"D" (rw), "i" (RW_LOCK_BIAS) : "memory"); } static inline void __raw_write_lock(raw_rwlock_t *rw) { - __build_write_lock(rw); + asm volatile(LOCK_PREFIX "subl %1,(%0)\n\t" + "jz 1f\n" + "\tcall __write_lock_failed\n\t" + "1:\n" + ::"D" (rw), "i" (RW_LOCK_BIAS) : "memory"); } static inline int __raw_read_trylock(raw_rwlock_t *lock)