mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 2/2] posix-timers: lock_timer: make it readable
@ 2008-08-05 15:32 Oleg Nesterov
  2008-08-05 15:40 ` Oleg Nesterov
  0 siblings, 1 reply; 2+ messages in thread
From: Oleg Nesterov @ 2008-08-05 15:32 UTC (permalink / raw)
  To: Andrew Morton; +Cc: Roland McGrath, Thomas Gleixner, linux-kernel

Cleanup. Imho makes the code much more understandable. At least this
patch lessens both the source and compiled code.

Signed-off-by: Oleg Nesterov <oleg@tv-sign.ru>

--- 26-rc2/kernel/posix-timers.c~10_LOCK_TIMER	2008-08-05 17:56:33.000000000 +0400
+++ 26-rc2/kernel/posix-timers.c	2008-08-05 18:53:19.000000000 +0400
@@ -557,7 +557,7 @@ out:
  * the find to the timer lock.  To avoid a dead lock, the timer id MUST
  * be release with out holding the timer lock.
  */
-static struct k_itimer * lock_timer(timer_t timer_id, unsigned long *flags)
+static struct k_itimer *lock_timer(timer_t timer_id, unsigned long *flags)
 {
 	struct k_itimer *timr;
 	/*
@@ -565,23 +565,20 @@ static struct k_itimer * lock_timer(time
 	 * flags part over to the timer lock.  Must not let interrupts in
 	 * while we are moving the lock.
 	 */
-
 	spin_lock_irqsave(&idr_lock, *flags);
-	timr = idr_find(&posix_timers_id, (int) timer_id);
+	timr = idr_find(&posix_timers_id, (int)timer_id);
 	if (timr) {
 		spin_lock(&timr->it_lock);
-
-		if (!timr->it_process ||
-		    !same_thread_group(timr->it_process, current)) {
-			spin_unlock(&timr->it_lock);
-			spin_unlock_irqrestore(&idr_lock, *flags);
-			timr = NULL;
-		} else
+		if (timr->it_process &&
+		    same_thread_group(timr->it_process, current)) {
 			spin_unlock(&idr_lock);
-	} else
-		spin_unlock_irqrestore(&idr_lock, *flags);
+			return timr;
+		}
+		spin_unlock(&timr->it_lock);
+	}
+	spin_unlock_irqrestore(&idr_lock, *flags);
 
-	return timr;
+	return NULL;
 }
 
 /*


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH 2/2] posix-timers: lock_timer: make it readable
  2008-08-05 15:32 [PATCH 2/2] posix-timers: lock_timer: make it readable Oleg Nesterov
@ 2008-08-05 15:40 ` Oleg Nesterov
  0 siblings, 0 replies; 2+ messages in thread
From: Oleg Nesterov @ 2008-08-05 15:40 UTC (permalink / raw)
  To: Andrew Morton; +Cc: Roland McGrath, Thomas Gleixner, linux-kernel

On 08/05, Oleg Nesterov wrote:
>
> Cleanup. Imho makes the code much more understandable. At least this
> patch lessens both the source and compiled code.

To simplify the review, I am posting the code with this patch applied.

static struct k_itimer *lock_timer(timer_t timer_id, unsigned long *flags)
{
	struct k_itimer *timr;
	/*
	 * Watch out here.  We do a irqsave on the idr_lock and pass the
	 * flags part over to the timer lock.  Must not let interrupts in
	 * while we are moving the lock.
	 */
	spin_lock_irqsave(&idr_lock, *flags);
	timr = idr_find(&posix_timers_id, (int)timer_id);
	if (timr) {
		spin_lock(&timr->it_lock);
		if (timr->it_process &&
		    same_thread_group(timr->it_process, current)) {
			spin_unlock(&idr_lock);
			return timr;
		}
		spin_unlock(&timr->it_lock);
	}
	spin_unlock_irqrestore(&idr_lock, *flags);

	return NULL;
}

Oleg.


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2008-08-05 15:36 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-08-05 15:32 [PATCH 2/2] posix-timers: lock_timer: make it readable Oleg Nesterov
2008-08-05 15:40 ` Oleg Nesterov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®