From 514a0b3e31428fe946b83e713190cb10fdf92f1a Mon Sep 17 00:00:00 2001 From: Michel Lespinasse Date: Tue, 7 May 2013 06:45:57 -0700 Subject: [PATCH] --- yaml --- r: 373753 b: refs/heads/master c: 9b0fc9c09f1b262b7fe697eba6b05095d78850e5 h: refs/heads/master i: 373751: 933598be8552f313a22601ff32256b673d3f0642 v: v3 --- [refs] | 2 +- trunk/lib/rwsem.c | 17 +++++++++-------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/[refs] b/[refs] index 6eb996896538..10353b0b1133 100644 --- a/[refs] +++ b/[refs] @@ -1,2 +1,2 @@ --- -refs/heads/master: a7d2c573ae7fad1b2c877d1a1342fa5bb0d6478c +refs/heads/master: 9b0fc9c09f1b262b7fe697eba6b05095d78850e5 diff --git a/trunk/lib/rwsem.c b/trunk/lib/rwsem.c index edf3d9ca670e..0d50e46d5b0c 100644 --- a/trunk/lib/rwsem.c +++ b/trunk/lib/rwsem.c @@ -216,14 +216,15 @@ struct rw_semaphore __sched *rwsem_down_write_failed(struct rw_semaphore *sem) /* wait until we successfully acquire the lock */ set_task_state(tsk, TASK_UNINTERRUPTIBLE); while (true) { - - /* Try acquiring the write lock. */ - count = RWSEM_ACTIVE_WRITE_BIAS; - if (!list_is_singular(&sem->wait_list)) - count += RWSEM_WAITING_BIAS; - if (cmpxchg(&sem->count, RWSEM_WAITING_BIAS, count) == + if (!(count & RWSEM_ACTIVE_MASK)) { + /* Try acquiring the write lock. */ + count = RWSEM_ACTIVE_WRITE_BIAS; + if (!list_is_singular(&sem->wait_list)) + count += RWSEM_WAITING_BIAS; + if (cmpxchg(&sem->count, RWSEM_WAITING_BIAS, count) == RWSEM_WAITING_BIAS) - break; + break; + } raw_spin_unlock_irq(&sem->wait_lock); @@ -231,7 +232,7 @@ struct rw_semaphore __sched *rwsem_down_write_failed(struct rw_semaphore *sem) do { schedule(); set_task_state(tsk, TASK_UNINTERRUPTIBLE); - } while (sem->count & RWSEM_ACTIVE_MASK); + } while ((count = sem->count) & RWSEM_ACTIVE_MASK); raw_spin_lock_irq(&sem->wait_lock); }