lkml.org 
[lkml]   [2010]   [May]   [11]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH 04/12] rwsem: consistently use adjustment variable
Date
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@google.com>
---
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


\
 
 \ /
  Last update: 2010-05-12 10:17    [W:0.154 / U:6.264 seconds]
©2003-2018 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site