From owner-freebsd-current Tue Jul 2 7:54:31 2002 Delivered-To: freebsd-current@freebsd.org Received: from mx1.FreeBSD.org (mx1.FreeBSD.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 9B87A37B405 for ; Tue, 2 Jul 2002 07:54:25 -0700 (PDT) Received: from prism.flugsvamp.com (66-191-112-47.mad.wi.charter.com [66.191.112.47]) by mx1.FreeBSD.org (Postfix) with ESMTP id E45BF43E09 for ; Tue, 2 Jul 2002 07:54:24 -0700 (PDT) (envelope-from jlemon@flugsvamp.com) Received: (from jlemon@localhost) by prism.flugsvamp.com (8.11.6/8.11.6) id g62Es2D56997 for current@freebsd.org; Tue, 2 Jul 2002 09:54:02 -0500 (CDT) (envelope-from jlemon) Date: Tue, 2 Jul 2002 09:54:02 -0500 From: Jonathan Lemon To: current@freebsd.org Subject: additional queue macro Message-ID: <20020702095402.D1020@prism.flugsvamp.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 1.0pre2i Sender: owner-freebsd-current@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG What do people think about adding the following macro to ? (I don't care much about the name, just the functionality) #define TAILQ_FOREACH_TMP(var, tmp, head, field) \ for ((var) = TAILQ_FIRST((head)); \ (var) && (((tmp) = TAILQ_NEXT((var), field)) || 1); \ (var) = (tmp)) Essentially, this provides a traversal of the tailq that is safe from element removal, while being simple to drop in to those sections of the code that need updating, as evidenced in the patch below. -- Jonathan Index: uthread_kern.c =================================================================== RCS file: /ncvs/src/lib/libc_r/uthread/uthread_kern.c,v retrieving revision 1.40 diff -u -r1.40 uthread_kern.c --- uthread_kern.c 2002/02/09 19:58:41 1.40 +++ uthread_kern.c 2002/07/02 14:52:00 @@ -664,7 +664,7 @@ int kern_pipe_added = 0; int nfds = 0; int timeout_ms = 0; - struct pthread *pthread; + struct pthread *pthread, *pthread_next; struct timespec ts; struct timeval tv; @@ -746,7 +746,7 @@ } PTHREAD_WAITQ_SETACTIVE(); - TAILQ_FOREACH(pthread, &_workq, qe) { + TAILQ_FOREACH_TMP(pthread, pthread_next, &_workq, qe) { switch (pthread->state) { case PS_SPINBLOCK: /* @@ -858,7 +858,7 @@ * _poll syscall: */ PTHREAD_WAITQ_SETACTIVE(); - TAILQ_FOREACH(pthread, &_workq, qe) { + TAILQ_FOREACH_TMP(pthread, pthread_next, &_workq, qe) { switch (pthread->state) { case PS_SPINBLOCK: /* @@ -947,7 +947,7 @@ * that is now available. */ PTHREAD_WAITQ_SETACTIVE(); - TAILQ_FOREACH(pthread, &_workq, qe) { + TAILQ_FOREACH_TMP(pthread, pthread_next, &_workq, qe) { if (pthread->state == PS_SPINBLOCK) { /* * If the lock is available, let the thread run. To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-current" in the body of the message