mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Robert P. J. Day" <rpjday@crashcourse.ca>
To: Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Cc: Andrew Morton <akpm@osdl.org>
Subject: [PATCH] RWSEM: Rewrite rwsem.c and rwsem-spinlock.c more simply.
Date: Tue, 25 Mar 2008 07:02:10 -0400 (EDT)	[thread overview]
Message-ID: <alpine.LFD.1.00.0803250659530.18358@localhost.localdomain> (raw)


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@crashcourse.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
========================================================================

             reply	other threads:[~2008-03-25 11:02 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-03-25 11:02 Robert P. J. Day [this message]
2008-03-25 12:08 ` Andi Kleen
2008-03-25 12:27   ` Robert P. J. Day
2008-03-25 12:36     ` Andi Kleen
2008-03-25 12:42       ` Robert P. J. Day
2008-03-25 19:14         ` Andrew Morton

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=alpine.LFD.1.00.0803250659530.18358@localhost.localdomain \
    --to=rpjday@crashcourse.ca \
    --cc=akpm@osdl.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome