X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=include%2Fasm-x86_64%2Fspinlock.h;h=5aeb57a3baad30b7111aa28cc6149cf891394bd5;hb=6a77f38946aaee1cd85eeec6cf4229b204c15071;hp=185e087e88ab821acd287082ecd506a4335691e9;hpb=87fc8d1bb10cd459024a742c6a10961fefcef18f;p=linux-2.6.git diff --git a/include/asm-x86_64/spinlock.h b/include/asm-x86_64/spinlock.h index 185e087e8..5aeb57a3b 100644 --- a/include/asm-x86_64/spinlock.h +++ b/include/asm-x86_64/spinlock.h @@ -18,6 +18,9 @@ typedef struct { #ifdef CONFIG_DEBUG_SPINLOCK unsigned magic; #endif +#ifdef CONFIG_PREEMPT + unsigned int break_lock; +#endif } spinlock_t; #define SPINLOCK_MAGIC 0xdead4ead @@ -72,7 +75,7 @@ static inline void _raw_spin_unlock(spinlock_t *lock) { #ifdef CONFIG_DEBUG_SPINLOCK BUG_ON(lock->magic != SPINLOCK_MAGIC); - BUG_ON(!spin_is_locked(lock)); + assert_spin_locked(lock); #endif __asm__ __volatile__( spin_unlock_string @@ -91,7 +94,7 @@ static inline void _raw_spin_unlock(spinlock_t *lock) char oldval = 1; #ifdef CONFIG_DEBUG_SPINLOCK BUG_ON(lock->magic != SPINLOCK_MAGIC); - BUG_ON(!spin_is_locked(lock)); + assert_spin_locked(lock); #endif __asm__ __volatile__( spin_unlock_string @@ -139,6 +142,9 @@ typedef struct { #ifdef CONFIG_DEBUG_SPINLOCK unsigned magic; #endif +#ifdef CONFIG_PREEMPT + unsigned int break_lock; +#endif } rwlock_t; #define RWLOCK_MAGIC 0xdeaf1eed @@ -153,7 +159,8 @@ typedef struct { #define rwlock_init(x) do { *(x) = RW_LOCK_UNLOCKED; } while(0) -#define rwlock_is_locked(x) ((x)->lock != RW_LOCK_BIAS) +#define read_can_lock(x) ((int)(x)->lock > 0) +#define write_can_lock(x) ((x)->lock == RW_LOCK_BIAS) /* * On x86, we implement read-write locks as a 32-bit counter @@ -185,6 +192,16 @@ static inline void _raw_write_lock(rwlock_t *rw) #define _raw_read_unlock(rw) asm volatile("lock ; incl %0" :"=m" ((rw)->lock) : : "memory") #define _raw_write_unlock(rw) asm volatile("lock ; addl $" RW_LOCK_BIAS_STR ",%0":"=m" ((rw)->lock) : : "memory") +static inline int _raw_read_trylock(rwlock_t *lock) +{ + atomic_t *count = (atomic_t *)lock; + atomic_dec(count); + if (atomic_read(count) >= 0) + return 1; + atomic_inc(count); + return 0; +} + static inline int _raw_write_trylock(rwlock_t *lock) { atomic_t *count = (atomic_t *)lock;