Merge tag 'iwlwifi-for-john-2014-11-03' of git://git.kernel.org/pub/scm/linux/kernel...
[cascardo/linux.git] / kernel / locking / rwsem-xadd.c
index d6203fa..7628c3f 100644 (file)
@@ -246,19 +246,22 @@ struct rw_semaphore __sched *rwsem_down_read_failed(struct rw_semaphore *sem)
 
        return sem;
 }
+EXPORT_SYMBOL(rwsem_down_read_failed);
 
 static inline bool rwsem_try_write_lock(long count, struct rw_semaphore *sem)
 {
-       if (!(count & RWSEM_ACTIVE_MASK)) {
-               /* try acquiring the write lock */
-               if (sem->count == RWSEM_WAITING_BIAS &&
-                   cmpxchg(&sem->count, RWSEM_WAITING_BIAS,
-                           RWSEM_ACTIVE_WRITE_BIAS) == RWSEM_WAITING_BIAS) {
-                       if (!list_is_singular(&sem->wait_list))
-                               rwsem_atomic_update(RWSEM_WAITING_BIAS, sem);
-                       return true;
-               }
+       /*
+        * Try acquiring the write lock. Check count first in order
+        * to reduce unnecessary expensive cmpxchg() operations.
+        */
+       if (count == RWSEM_WAITING_BIAS &&
+           cmpxchg(&sem->count, RWSEM_WAITING_BIAS,
+                   RWSEM_ACTIVE_WRITE_BIAS) == RWSEM_WAITING_BIAS) {
+               if (!list_is_singular(&sem->wait_list))
+                       rwsem_atomic_update(RWSEM_WAITING_BIAS, sem);
+               return true;
        }
+
        return false;
 }
 
@@ -465,6 +468,7 @@ struct rw_semaphore __sched *rwsem_down_write_failed(struct rw_semaphore *sem)
 
        return sem;
 }
+EXPORT_SYMBOL(rwsem_down_write_failed);
 
 /*
  * handle waking up a waiter on the semaphore
@@ -485,6 +489,7 @@ struct rw_semaphore *rwsem_wake(struct rw_semaphore *sem)
 
        return sem;
 }
+EXPORT_SYMBOL(rwsem_wake);
 
 /*
  * downgrade a write lock into a read lock
@@ -506,8 +511,4 @@ struct rw_semaphore *rwsem_downgrade_wake(struct rw_semaphore *sem)
 
        return sem;
 }
-
-EXPORT_SYMBOL(rwsem_down_read_failed);
-EXPORT_SYMBOL(rwsem_down_write_failed);
-EXPORT_SYMBOL(rwsem_wake);
 EXPORT_SYMBOL(rwsem_downgrade_wake);