[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <alpine.LFD.1.00.0803250659530.18358@localhost.localdomain>
Date: Tue, 25 Mar 2008 07:02:10 -0400 (EDT)
From: "Robert P. J. Day" <rpjday@...shcourse.ca>
To: Linux Kernel Mailing List <linux-kernel@...r.kernel.org>
cc: Andrew Morton <akpm@...l.org>
Subject: [PATCH] RWSEM: Rewrite rwsem.c and rwsem-spinlock.c more simply.
Rewrite these source files more simply by deleting the superfluous
"tsk" task_struct pointer and rephrasing in terms of the "current"
task pointer.
Signed-off-by: Robert P. J. Day <rpjday@...shcourse.ca>
---
in addition to making the code slightly simpler, this makes it
easier to read since there's more information in:
set_current_state(TASK_UNINTERRUPTIBLE);
as opposed to:
set_task_state(tsk, TASK_UNINTERRUPTIBLE);
if it's not clear what "tsk" refers to.
compile tested on x86 with "make defconfig", but that doesn't really
mean much since that configuration doesn't even compile the second of
those source files. so i'll leave it to someone who's a locking
expert to sanity check this. i'm quite willing to be told i screwed
something up.
lib/rwsem-spinlock.c | 24 ++++++++++--------------
lib/rwsem.c | 11 +++++------
2 files changed, 15 insertions(+), 20 deletions(-)
diff --git a/lib/rwsem-spinlock.c b/lib/rwsem-spinlock.c
index 9df3ca5..8c3fc63 100644
--- a/lib/rwsem-spinlock.c
+++ b/lib/rwsem-spinlock.c
@@ -128,7 +128,6 @@ __rwsem_wake_one_writer(struct rw_semaphore *sem)
void __sched __down_read(struct rw_semaphore *sem)
{
struct rwsem_waiter waiter;
- struct task_struct *tsk;
spin_lock_irq(&sem->wait_lock);
@@ -139,13 +138,12 @@ void __sched __down_read(struct rw_semaphore *sem)
goto out;
}
- tsk = current;
- set_task_state(tsk, TASK_UNINTERRUPTIBLE);
+ set_current_state(TASK_UNINTERRUPTIBLE);
/* set up my own style of waitqueue */
- waiter.task = tsk;
+ waiter.task = current;
waiter.flags = RWSEM_WAITING_FOR_READ;
- get_task_struct(tsk);
+ get_task_struct(current);
list_add_tail(&waiter.list, &sem->wait_list);
@@ -157,10 +155,10 @@ void __sched __down_read(struct rw_semaphore *sem)
if (!waiter.task)
break;
schedule();
- set_task_state(tsk, TASK_UNINTERRUPTIBLE);
+ set_current_state(TASK_UNINTERRUPTIBLE);
}
- tsk->state = TASK_RUNNING;
+ set_current_state(TASK_RUNNING);
out:
;
}
@@ -194,7 +192,6 @@ int __down_read_trylock(struct rw_semaphore *sem)
void __sched __down_write_nested(struct rw_semaphore *sem, int subclass)
{
struct rwsem_waiter waiter;
- struct task_struct *tsk;
spin_lock_irq(&sem->wait_lock);
@@ -205,13 +202,12 @@ void __sched __down_write_nested(struct rw_semaphore *sem, int subclass)
goto out;
}
- tsk = current;
- set_task_state(tsk, TASK_UNINTERRUPTIBLE);
+ set_current_state(TASK_UNINTERRUPTIBLE);
/* set up my own style of waitqueue */
- waiter.task = tsk;
+ waiter.task = current;
waiter.flags = RWSEM_WAITING_FOR_WRITE;
- get_task_struct(tsk);
+ get_task_struct(current);
list_add_tail(&waiter.list, &sem->wait_list);
@@ -223,10 +219,10 @@ void __sched __down_write_nested(struct rw_semaphore *sem, int subclass)
if (!waiter.task)
break;
schedule();
- set_task_state(tsk, TASK_UNINTERRUPTIBLE);
+ set_current_state(TASK_UNINTERRUPTIBLE);
}
- tsk->state = TASK_RUNNING;
+ set_current_state(TASK_RUNNING);
out:
;
}
diff --git a/lib/rwsem.c b/lib/rwsem.c
index 3e3365e..f1bdb97 100644
--- a/lib/rwsem.c
+++ b/lib/rwsem.c
@@ -150,15 +150,14 @@ static struct rw_semaphore __sched *
rwsem_down_failed_common(struct rw_semaphore *sem,
struct rwsem_waiter *waiter, signed long adjustment)
{
- struct task_struct *tsk = current;
signed long count;
- set_task_state(tsk, TASK_UNINTERRUPTIBLE);
+ set_current_state(TASK_UNINTERRUPTIBLE);
/* set up my own style of waitqueue */
spin_lock_irq(&sem->wait_lock);
- waiter->task = tsk;
- get_task_struct(tsk);
+ waiter->task = current;
+ get_task_struct(current);
list_add_tail(&waiter->list, &sem->wait_list);
@@ -176,10 +175,10 @@ rwsem_down_failed_common(struct rw_semaphore *sem,
if (!waiter->task)
break;
schedule();
- set_task_state(tsk, TASK_UNINTERRUPTIBLE);
+ set_current_state(TASK_UNINTERRUPTIBLE);
}
- tsk->state = TASK_RUNNING;
+ set_current_state(TASK_RUNNING);
return sem;
}
========================================================================
Robert P. J. Day
Linux Consulting, Training and Annoying Kernel Pedantry:
Have classroom, will lecture.
http://crashcourse.ca Waterloo, Ontario, CANADA
========================================================================
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists