[PATCH 04/12] rwsem: consistently use adjustment variable

From: Michel Lespinasse
Date: Tue May 11 2010 - 23:24:16 EST


Cleanup: previous change introduced an adjustment variable used in
waking writers; the code to wake readers can be made nicer by making
use of that same variable.

Reducing variable count should hopefully help both humans and compilers
looking at this function :)

Signed-off-by: Michel Lespinasse <walken@xxxxxxxxxx>
---
lib/rwsem.c | 15 +++++++--------
1 files changed, 7 insertions(+), 8 deletions(-)

diff --git a/lib/rwsem.c b/lib/rwsem.c
index 0fb6e38..92c8f8e 100644
--- a/lib/rwsem.c
+++ b/lib/rwsem.c
@@ -52,7 +52,7 @@ __rwsem_do_wake(struct rw_semaphore *sem, int downgrading)
struct rwsem_waiter *waiter;
struct task_struct *tsk;
struct list_head *next;
- signed long oldcount, woken, loop, adjustment;
+ signed long oldcount, loop, adjustment;

waiter = list_entry(sem->wait_list.next, struct rwsem_waiter, list);
if (!(waiter->flags & RWSEM_WAITING_FOR_WRITE))
@@ -96,9 +96,9 @@ __rwsem_do_wake(struct rw_semaphore *sem, int downgrading)
* readers before waking any processes up
*/
readers_only:
- woken = 0;
+ loop = 0;
do {
- woken++;
+ loop++;

if (waiter->list.next == &sem->wait_list)
break;
@@ -108,14 +108,13 @@ __rwsem_do_wake(struct rw_semaphore *sem, int downgrading)

} while (waiter->flags & RWSEM_WAITING_FOR_READ);

- loop = woken;
- woken *= RWSEM_ACTIVE_READ_BIAS;
+ adjustment = loop * RWSEM_ACTIVE_READ_BIAS;
if (waiter->flags & RWSEM_WAITING_FOR_READ)
/* hit end of list above */
- woken -= RWSEM_WAITING_BIAS;
+ adjustment -= RWSEM_WAITING_BIAS;

retry_readers:
- oldcount = rwsem_atomic_update(woken, sem) - woken;
+ oldcount = rwsem_atomic_update(adjustment, sem) - adjustment;
if (!downgrading && (oldcount & RWSEM_ACTIVE_MASK))
/* Someone grabbed the sem already */
goto undo_readers;
@@ -144,7 +143,7 @@ __rwsem_do_wake(struct rw_semaphore *sem, int downgrading)
goto retry_writer;

undo_readers:
- if (rwsem_atomic_update(-woken, sem) & RWSEM_ACTIVE_MASK)
+ if (rwsem_atomic_update(-adjustment, sem) & RWSEM_ACTIVE_MASK)
goto out;
goto retry_readers;
}
--
1.7.0.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/