Merge branch 'for-2.6.35' of git://linux-nfs.org/~bfields/linux
[safe/jmp/linux-2.6] / lib / rwsem-spinlock.c
index 39a7411..ffc9fc7 100644 (file)
@@ -17,6 +17,19 @@ struct rwsem_waiter {
 #define RWSEM_WAITING_FOR_WRITE        0x00000002
 };
 
+int rwsem_is_locked(struct rw_semaphore *sem)
+{
+       int ret = 1;
+       unsigned long flags;
+
+       if (spin_trylock_irqsave(&sem->wait_lock, flags)) {
+               ret = (sem->activity != 0);
+               spin_unlock_irqrestore(&sem->wait_lock, flags);
+       }
+       return ret;
+}
+EXPORT_SYMBOL(rwsem_is_locked);
+
 /*
  * initialise the semaphore
  */
@@ -130,13 +143,14 @@ void __sched __down_read(struct rw_semaphore *sem)
 {
        struct rwsem_waiter waiter;
        struct task_struct *tsk;
+       unsigned long flags;
 
-       spin_lock_irq(&sem->wait_lock);
+       spin_lock_irqsave(&sem->wait_lock, flags);
 
        if (sem->activity >= 0 && list_empty(&sem->wait_list)) {
                /* granted */
                sem->activity++;
-               spin_unlock_irq(&sem->wait_lock);
+               spin_unlock_irqrestore(&sem->wait_lock, flags);
                goto out;
        }
 
@@ -151,7 +165,7 @@ void __sched __down_read(struct rw_semaphore *sem)
        list_add_tail(&waiter.list, &sem->wait_list);
 
        /* we don't need to touch the semaphore struct anymore */
-       spin_unlock_irq(&sem->wait_lock);
+       spin_unlock_irqrestore(&sem->wait_lock, flags);
 
        /* wait to be given the lock */
        for (;;) {
@@ -196,13 +210,14 @@ void __sched __down_write_nested(struct rw_semaphore *sem, int subclass)
 {
        struct rwsem_waiter waiter;
        struct task_struct *tsk;
+       unsigned long flags;
 
-       spin_lock_irq(&sem->wait_lock);
+       spin_lock_irqsave(&sem->wait_lock, flags);
 
        if (sem->activity == 0 && list_empty(&sem->wait_list)) {
                /* granted */
                sem->activity = -1;
-               spin_unlock_irq(&sem->wait_lock);
+               spin_unlock_irqrestore(&sem->wait_lock, flags);
                goto out;
        }
 
@@ -217,7 +232,7 @@ void __sched __down_write_nested(struct rw_semaphore *sem, int subclass)
        list_add_tail(&waiter.list, &sem->wait_list);
 
        /* we don't need to touch the semaphore struct anymore */
-       spin_unlock_irq(&sem->wait_lock);
+       spin_unlock_irqrestore(&sem->wait_lock, flags);
 
        /* wait to be given the lock */
        for (;;) {