From owner-p4-projects@FreeBSD.ORG Wed Jul 5 15:16:48 2006 Return-Path: X-Original-To: p4-projects@freebsd.org Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id DE87516A4E2; Wed, 5 Jul 2006 15:16:47 +0000 (UTC) X-Original-To: perforce@freebsd.org Delivered-To: perforce@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id A513816A4E7 for ; Wed, 5 Jul 2006 15:16:47 +0000 (UTC) (envelope-from piso@freebsd.org) Received: from repoman.freebsd.org (repoman.freebsd.org [216.136.204.115]) by mx1.FreeBSD.org (Postfix) with ESMTP id 45DB643D53 for ; Wed, 5 Jul 2006 15:16:47 +0000 (GMT) (envelope-from piso@freebsd.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.13.6/8.13.6) with ESMTP id k65FGlue059776 for ; Wed, 5 Jul 2006 15:16:47 GMT (envelope-from piso@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.13.6/8.13.4/Submit) id k65FGl0o059773 for perforce@freebsd.org; Wed, 5 Jul 2006 15:16:47 GMT (envelope-from piso@freebsd.org) Date: Wed, 5 Jul 2006 15:16:47 GMT Message-Id: <200607051516.k65FGl0o059773@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to piso@freebsd.org using -f From: Paolo Pisati To: Perforce Change Reviews Cc: Subject: PERFORCE change 100631 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 05 Jul 2006 15:16:48 -0000 http://perforce.freebsd.org/chv.cgi?CH=100631 Change 100631 by piso@piso_newluxor on 2006/07/05 15:15:46 Convert dll to queue(3). Affected files ... .. //depot/projects/soc2005/libalias/sys/netinet/libalias/alias_mod.c#10 edit .. //depot/projects/soc2005/libalias/sys/netinet/libalias/alias_mod.h#10 edit Differences ... ==== //depot/projects/soc2005/libalias/sys/netinet/libalias/alias_mod.c#10 (text+ko) ==== @@ -61,7 +61,7 @@ /* protocol and userland module handlers chains */ struct chain handler_chain; -struct dll *dll_chain; +SLIST_HEAD(dll_chain, dll) dll_chain = SLIST_HEAD_INITIALIZER(foo); #ifdef _KERNEL @@ -257,55 +257,38 @@ /* dll manipulation code - this code is not thread safe... */ -static int -_attach_dll(struct dll **b, struct dll *p) { - int i = 0; +int +attach_dll(struct dll *p) { + struct dll *b; - p->next = NULL; /* i'm paranoid... */ - for(; *b != NULL; b = &((*b)->next), i++) - if (!strncmp((*b)->name, p->name, DLL_LEN)) + SLIST_FOREACH(b, &dll_chain, next) { + if (!strncmp(b->name, p->name, DLL_LEN)) return (EHDCON); /* dll name conflict */ + } /* end of list, insert here */ - *b = p; + SLIST_INSERT_HEAD(&dll_chain, p, next); return (OK); } -static void * -_detach_dll(struct dll **b, char *p) { - void *err = NULL; +void * +detach_dll(char *p) { + struct dll *b = NULL, *b_tmp; + void *error = NULL; - for(; *b != NULL; b = &((*b)->next)) - if (!strncmp((*b)->name, p, DLL_LEN)) { - err = *b; - *b = (*b)->next; + SLIST_FOREACH_SAFE(b, &dll_chain, next, b_tmp) + if (!strncmp(b->name, p, DLL_LEN)) { + SLIST_REMOVE(&dll_chain, b, dll, next); + error = b; break; } - return (err); -} - -int -attach_dll(struct dll *p) { - int i; - - i = _attach_dll(&dll_chain, p); - return (i); -} - -void * -detach_dll(char *p) { - void *i; - - i = _detach_dll(&dll_chain, p); - return (i); + return (error); } struct dll * walk_dll_chain(void) { - struct dll *t, **b = &dll_chain; + struct dll *t; - for(t = *b; *b != NULL;) { - *b = (*b)->next; - break; - } + t = SLIST_FIRST(&dll_chain); + SLIST_REMOVE_HEAD(&dll_chain, next); return (t); } ==== //depot/projects/soc2005/libalias/sys/netinet/libalias/alias_mod.h#10 (text+ko) ==== @@ -86,12 +86,6 @@ struct rwlock rw; }; -struct dll_chain { - void *chain; - // XXX - what if a process with 2 threads manipulate the - // libalias dll list? we still need a lock here... -}; - /* * Used only in userland when libalias needs to keep track of all * module loaded. In kernel land (kld mode) we don't need to care @@ -107,7 +101,7 @@ * to any symbols from a loaded module * via dlsym(). */ - struct dll *next; + SLIST_ENTRY(dll) next; }; /* Functions used with protocol handlers. */