Module Name:    src
Committed By:   yamt
Date:           Mon Oct 31 12:18:32 UTC 2011

Modified Files:
        src/sys/kern: kern_sleepq.c
        src/sys/sys: lwp.h

Log Message:
- make lendpri/changepri similar.
- make common code a subroutine.


To generate a diff of this commit:
cvs rdiff -u -r1.43 -r1.44 src/sys/kern/kern_sleepq.c
cvs rdiff -u -r1.155 -r1.156 src/sys/sys/lwp.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/kern/kern_sleepq.c
diff -u src/sys/kern/kern_sleepq.c:1.43 src/sys/kern/kern_sleepq.c:1.44
--- src/sys/kern/kern_sleepq.c:1.43	Sat Sep  3 10:28:33 2011
+++ src/sys/kern/kern_sleepq.c	Mon Oct 31 12:18:32 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_sleepq.c,v 1.43 2011/09/03 10:28:33 christos Exp $	*/
+/*	$NetBSD: kern_sleepq.c,v 1.44 2011/10/31 12:18:32 yamt Exp $	*/
 
 /*-
  * Copyright (c) 2006, 2007, 2008, 2009 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_sleepq.c,v 1.43 2011/09/03 10:28:33 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_sleepq.c,v 1.44 2011/10/31 12:18:32 yamt Exp $");
 
 #include <sys/param.h>
 #include <sys/kernel.h>
@@ -422,26 +422,16 @@ sleepq_abort(kmutex_t *mtx, int unlock)
 }
 
 /*
- * sleepq_changepri:
+ * sleepq_reinsert:
  *
- *	Adjust the priority of an LWP residing on a sleepq.  This method
- *	will only alter the user priority; the effective priority is
- *	assumed to have been fixed at the time of insertion into the queue.
+ *	Move the possition of the lwp in the sleep queue after a possible
+ *	change of the lwp's effective priority.
  */
-void
-sleepq_changepri(lwp_t *l, pri_t pri)
+static void
+sleepq_reinsert(sleepq_t *sq, lwp_t *l)
 {
-	sleepq_t *sq = l->l_sleepq;
-	pri_t opri;
-
-	KASSERT(lwp_locked(l, NULL));
 
-	opri = lwp_eprio(l);
-	l->l_priority = pri;
-
-	if (lwp_eprio(l) == opri) {
-		return;
-	}
+	KASSERT(l->l_sleepq == sq);
 	if ((l->l_syncobj->sobj_flag & SOBJ_SLEEPQ_SORTED) == 0) {
 		return;
 	}
@@ -459,33 +449,34 @@ sleepq_changepri(lwp_t *l, pri_t pri)
 	sleepq_insert(sq, l, l->l_syncobj);
 }
 
+/*
+ * sleepq_changepri:
+ *
+ *	Adjust the priority of an LWP residing on a sleepq.
+ */
 void
-sleepq_lendpri(lwp_t *l, pri_t pri)
+sleepq_changepri(lwp_t *l, pri_t pri)
 {
 	sleepq_t *sq = l->l_sleepq;
-	pri_t opri;
 
 	KASSERT(lwp_locked(l, NULL));
 
-	opri = lwp_eprio(l);
-	l->l_inheritedprio = pri;
+	l->l_priority = pri;
+	sleepq_reinsert(sq, l);
+}
 
-	if (lwp_eprio(l) == opri) {
-		return;
-	}
-	if ((l->l_syncobj->sobj_flag & SOBJ_SLEEPQ_SORTED) == 0) {
-		return;
-	}
+/*
+ * sleepq_changepri:
+ *
+ *	Adjust the lended priority of an LWP residing on a sleepq.
+ */
+void
+sleepq_lendpri(lwp_t *l, pri_t pri)
+{
+	sleepq_t *sq = l->l_sleepq;
 
-	/*
-	 * Don't let the sleep queue become empty, even briefly.
-	 * cv_signal() and cv_broadcast() inspect it without the
-	 * sleep queue lock held and need to see a non-empty queue
-	 * head if there are waiters.
-	 */
-	if (TAILQ_FIRST(sq) == l && TAILQ_NEXT(l, l_sleepchain) == NULL) {
-		return;
-	}
-	TAILQ_REMOVE(sq, l, l_sleepchain);
-	sleepq_insert(sq, l, l->l_syncobj);
+	KASSERT(lwp_locked(l, NULL));
+
+	l->l_inheritedprio = pri;
+	sleepq_reinsert(sq, l);
 }

Index: src/sys/sys/lwp.h
diff -u src/sys/sys/lwp.h:1.155 src/sys/sys/lwp.h:1.156
--- src/sys/sys/lwp.h:1.155	Sun Aug  7 21:13:06 2011
+++ src/sys/sys/lwp.h	Mon Oct 31 12:18:32 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: lwp.h,v 1.155 2011/08/07 21:13:06 rmind Exp $	*/
+/*	$NetBSD: lwp.h,v 1.156 2011/10/31 12:18:32 yamt Exp $	*/
 
 /*-
  * Copyright (c) 2001, 2006, 2007, 2008, 2009, 2010
@@ -392,7 +392,11 @@ lwp_changepri(lwp_t *l, pri_t pri)
 {
 	KASSERT(mutex_owned(l->l_mutex));
 
+	if (l->l_priority == pri)
+		return;
+
 	(*l->l_syncobj->sobj_changepri)(l, pri);
+	KASSERT(l->l_priority == pri);
 }
 
 static inline void
@@ -404,6 +408,7 @@ lwp_lendpri(lwp_t *l, pri_t pri)
 		return;
 
 	(*l->l_syncobj->sobj_lendpri)(l, pri);
+	KASSERT(l->l_inheritedprio == pri);
 }
 
 static inline pri_t

Reply via email to