Merge with /pub/scm/linux/kernel/git/torvalds/linux-2.6.git
[powerpc.git] / arch / s390 / lib / spinlock.c
index 2dc14e9..b9b7958 100644 (file)
@@ -2,8 +2,7 @@
  *  arch/s390/lib/spinlock.c
  *    Out of line spinlock code.
  *
- *  S390 version
- *    Copyright (C) 2004 IBM Deutschland Entwicklung GmbH, IBM Corporation
+ *    Copyright (C) IBM Corp. 2004, 2006
  *    Author(s): Martin Schwidefsky (schwidefsky@de.ibm.com)
  */
 
@@ -13,7 +12,6 @@
 #include <linux/init.h>
 #include <asm/io.h>
 
-atomic_t spin_retry_counter;
 int spin_retry = 1000;
 
 /**
@@ -29,7 +27,7 @@ __setup("spin_retry=", spin_retry_setup);
 static inline void
 _diag44(void)
 {
-#ifdef __s390x__
+#ifdef CONFIG_64BIT
        if (MACHINE_HAS_DIAG44)
 #endif
                asm volatile("diag 0,0,0x44");
@@ -45,7 +43,8 @@ _raw_spin_lock_wait(raw_spinlock_t *lp, unsigned int pc)
                        _diag44();
                        count = spin_retry;
                }
-               atomic_inc(&spin_retry_counter);
+               if (__raw_spin_is_locked(lp))
+                       continue;
                if (_raw_compare_and_swap(&lp->lock, 0, pc) == 0)
                        return;
        }
@@ -58,7 +57,8 @@ _raw_spin_trylock_retry(raw_spinlock_t *lp, unsigned int pc)
        int count = spin_retry;
 
        while (count-- > 0) {
-               atomic_inc(&spin_retry_counter);
+               if (__raw_spin_is_locked(lp))
+                       continue;
                if (_raw_compare_and_swap(&lp->lock, 0, pc) == 0)
                        return 1;
        }
@@ -77,7 +77,8 @@ _raw_read_lock_wait(raw_rwlock_t *rw)
                        _diag44();
                        count = spin_retry;
                }
-               atomic_inc(&spin_retry_counter);
+               if (!__raw_read_can_lock(rw))
+                       continue;
                old = rw->lock & 0x7fffffffU;
                if (_raw_compare_and_swap(&rw->lock, old, old + 1) == old)
                        return;
@@ -92,7 +93,8 @@ _raw_read_trylock_retry(raw_rwlock_t *rw)
        int count = spin_retry;
 
        while (count-- > 0) {
-               atomic_inc(&spin_retry_counter);
+               if (!__raw_read_can_lock(rw))
+                       continue;
                old = rw->lock & 0x7fffffffU;
                if (_raw_compare_and_swap(&rw->lock, old, old + 1) == old)
                        return 1;
@@ -111,7 +113,8 @@ _raw_write_lock_wait(raw_rwlock_t *rw)
                        _diag44();
                        count = spin_retry;
                }
-               atomic_inc(&spin_retry_counter);
+               if (!__raw_write_can_lock(rw))
+                       continue;
                if (_raw_compare_and_swap(&rw->lock, 0, 0x80000000) == 0)
                        return;
        }
@@ -124,7 +127,8 @@ _raw_write_trylock_retry(raw_rwlock_t *rw)
        int count = spin_retry;
 
        while (count-- > 0) {
-               atomic_inc(&spin_retry_counter);
+               if (!__raw_write_can_lock(rw))
+                       continue;
                if (_raw_compare_and_swap(&rw->lock, 0, 0x80000000) == 0)
                        return 1;
        }