Merge to Fedora kernel-2.6.18-1.2224_FC5 patched with stable patch-2.6.18.1-vs2.0...
[linux-2.6.git] / include / asm-i386 / rwsem.h
index be4ab85..43113f5 100644 (file)
@@ -40,6 +40,7 @@
 
 #include <linux/list.h>
 #include <linux/spinlock.h>
+#include <linux/lockdep.h>
 
 struct rwsem_waiter;
 
@@ -61,36 +62,34 @@ struct rw_semaphore {
 #define RWSEM_ACTIVE_WRITE_BIAS                (RWSEM_WAITING_BIAS + RWSEM_ACTIVE_BIAS)
        spinlock_t              wait_lock;
        struct list_head        wait_list;
-#if RWSEM_DEBUG
-       int                     debug;
+#ifdef CONFIG_DEBUG_LOCK_ALLOC
+       struct lockdep_map dep_map;
 #endif
 };
 
-/*
- * initialisation
- */
-#if RWSEM_DEBUG
-#define __RWSEM_DEBUG_INIT      , 0
+#ifdef CONFIG_DEBUG_LOCK_ALLOC
+# define __RWSEM_DEP_MAP_INIT(lockname) , .dep_map = { .name = #lockname }
 #else
-#define __RWSEM_DEBUG_INIT     /* */
+# define __RWSEM_DEP_MAP_INIT(lockname)
 #endif
 
+
 #define __RWSEM_INITIALIZER(name) \
 { RWSEM_UNLOCKED_VALUE, SPIN_LOCK_UNLOCKED, LIST_HEAD_INIT((name).wait_list) \
-       __RWSEM_DEBUG_INIT }
+       __RWSEM_DEP_MAP_INIT(name) }
 
 #define DECLARE_RWSEM(name) \
        struct rw_semaphore name = __RWSEM_INITIALIZER(name)
 
-static inline void init_rwsem(struct rw_semaphore *sem)
-{
-       sem->count = RWSEM_UNLOCKED_VALUE;
-       spin_lock_init(&sem->wait_lock);
-       INIT_LIST_HEAD(&sem->wait_list);
-#if RWSEM_DEBUG
-       sem->debug = 0;
-#endif
-}
+extern void __init_rwsem(struct rw_semaphore *sem, const char *name,
+                        struct lock_class_key *key);
+
+#define init_rwsem(sem)                                                \
+do {                                                           \
+       static struct lock_class_key __key;                     \
+                                                               \
+       __init_rwsem((sem), #sem, &__key);                      \
+} while (0)
 
 /*
  * lock for reading
@@ -112,8 +111,8 @@ LOCK_PREFIX "  incl      (%%eax)\n\t" /* adds 0x00000001, returns the old value
                "  jmp       1b\n"
                LOCK_SECTION_END
                "# ending down_read\n\t"
-               : "=m"(sem->count)
-               : "a"(sem), "m"(sem->count)
+               : "+m" (sem->count)
+               : "a" (sem)
                : "memory", "cc");
 }
 
@@ -134,8 +133,8 @@ LOCK_PREFIX "  cmpxchgl  %2,%0\n\t"
                "  jnz       1b\n\t"
                "2:\n\t"
                "# ending __down_read_trylock\n\t"
-               : "+m"(sem->count), "=&a"(result), "=&r"(tmp)
-               : "i"(RWSEM_ACTIVE_READ_BIAS)
+               : "+m" (sem->count), "=&a" (result), "=&r" (tmp)
+               : "i" (RWSEM_ACTIVE_READ_BIAS)
                : "memory", "cc");
        return result>=0 ? 1 : 0;
 }
@@ -143,7 +142,7 @@ LOCK_PREFIX "  cmpxchgl  %2,%0\n\t"
 /*
  * lock for writing
  */
-static inline void __down_write(struct rw_semaphore *sem)
+static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
 {
        int tmp;
 
@@ -162,11 +161,16 @@ LOCK_PREFIX       "  xadd      %%edx,(%%eax)\n\t" /* subtract 0x0000ffff, returns the
                "  jmp       1b\n"
                LOCK_SECTION_END
                "# ending down_write"
-               : "=m"(sem->count), "=d"(tmp)
-               : "a"(sem), "1"(tmp), "m"(sem->count)
+               : "+m" (sem->count), "=d" (tmp)
+               : "a" (sem), "1" (tmp)
                : "memory", "cc");
 }
 
+static inline void __down_write(struct rw_semaphore *sem)
+{
+       __down_write_nested(sem, 0);
+}
+
 /*
  * trylock for writing -- returns 1 if successful, 0 if contention
  */
@@ -201,8 +205,8 @@ LOCK_PREFIX "  xadd      %%edx,(%%eax)\n\t" /* subtracts 1, returns the old valu
                "  jmp       1b\n"
                LOCK_SECTION_END
                "# ending __up_read\n"
-               : "=m"(sem->count), "=d"(tmp)
-               : "a"(sem), "1"(tmp), "m"(sem->count)
+               : "+m" (sem->count), "=d" (tmp)
+               : "a" (sem), "1" (tmp)
                : "memory", "cc");
 }
 
@@ -227,8 +231,8 @@ LOCK_PREFIX "  xaddl     %%edx,(%%eax)\n\t" /* tries to transition 0xffff0001 ->
                "  jmp       1b\n"
                LOCK_SECTION_END
                "# ending __up_write\n"
-               : "=m"(sem->count)
-               : "a"(sem), "i"(-RWSEM_ACTIVE_WRITE_BIAS), "m"(sem->count)
+               : "+m" (sem->count)
+               : "a" (sem), "i" (-RWSEM_ACTIVE_WRITE_BIAS)
                : "memory", "cc", "edx");
 }
 
@@ -252,8 +256,8 @@ LOCK_PREFIX "  addl      %2,(%%eax)\n\t" /* transitions 0xZZZZ0001 -> 0xYYYY0001
                "  jmp       1b\n"
                LOCK_SECTION_END
                "# ending __downgrade_write\n"
-               : "=m"(sem->count)
-               : "a"(sem), "i"(-RWSEM_WAITING_BIAS), "m"(sem->count)
+               : "+m" (sem->count)
+               : "a" (sem), "i" (-RWSEM_WAITING_BIAS)
                : "memory", "cc");
 }
 
@@ -264,8 +268,8 @@ static inline void rwsem_atomic_add(int delta, struct rw_semaphore *sem)
 {
        __asm__ __volatile__(
 LOCK_PREFIX    "addl %1,%0"
-               : "=m"(sem->count)
-               : "ir"(delta), "m"(sem->count));
+               : "+m" (sem->count)
+               : "ir" (delta));
 }
 
 /*
@@ -276,10 +280,9 @@ static inline int rwsem_atomic_update(int delta, struct rw_semaphore *sem)
        int tmp = delta;
 
        __asm__ __volatile__(
-LOCK_PREFIX    "xadd %0,(%2)"
-               : "+r"(tmp), "=m"(sem->count)
-               : "r"(sem), "m"(sem->count)
-               : "memory");
+LOCK_PREFIX    "xadd %0,%1"
+               : "+r" (tmp), "+m" (sem->count)
+               : : "memory");
 
        return tmp+delta;
 }