From 727300861d57d2cc710a090995dca89ea0b3fb4d Mon Sep 17 00:00:00 2001 From: Matthew Dillon Date: Mon, 24 Jun 2002 00:14:36 +0000 Subject: I Noticed a defect in the way wakeup() scans the tailq. Tor noticed an even worse defect in wakeup_one(). This patch cleans up both. Submitted by: tegge MFC after: 3 days --- sys/kern/kern_synch.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'sys') diff --git a/sys/kern/kern_synch.c b/sys/kern/kern_synch.c index 9d959d22b706..6f9adaddc4db 100644 --- a/sys/kern/kern_synch.c +++ b/sys/kern/kern_synch.c @@ -606,12 +606,14 @@ wakeup(ident) { register struct slpquehead *qp; register struct thread *td; + struct thread *ntd; struct proc *p; mtx_lock_spin(&sched_lock); qp = &slpque[LOOKUP(ident)]; restart: - TAILQ_FOREACH(td, qp, td_slpq) { + for (td = TAILQ_FIRST(qp); td != NULL; td = ntd) { + ntd = TAILQ_NEXT(td, td_slpq); p = td->td_proc; if (td->td_wchan == ident) { TAILQ_REMOVE(qp, td, td_slpq); @@ -652,11 +654,13 @@ wakeup_one(ident) register struct slpquehead *qp; register struct thread *td; register struct proc *p; + struct thread *ntd; mtx_lock_spin(&sched_lock); qp = &slpque[LOOKUP(ident)]; - - TAILQ_FOREACH(td, qp, td_slpq) { +restart: + for (td = TAILQ_FIRST(qp); td != NULL; td = ntd) { + ntd = TAILQ_NEXT(td, td_slpq); p = td->td_proc; if (td->td_wchan == ident) { TAILQ_REMOVE(qp, td, td_slpq); @@ -679,6 +683,7 @@ wakeup_one(ident) wakeup((caddr_t)&proc0); } /* END INLINE EXPANSION */ + goto restart; } } } -- cgit v1.2.3