From owner-p4-projects@FreeBSD.ORG Thu May 25 21:48:10 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 19EDF16CCC0; Thu, 25 May 2006 21:42:18 +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 45EC516B21A for ; Thu, 25 May 2006 21:40:56 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from repoman.freebsd.org (repoman.freebsd.org [216.136.204.115]) by mx1.FreeBSD.org (Postfix) with ESMTP id 3631743D4C for ; Thu, 25 May 2006 21:40:52 +0000 (GMT) (envelope-from jhb@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 k4PLdtP9067318 for ; Thu, 25 May 2006 21:39:55 GMT (envelope-from jhb@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.13.6/8.13.4/Submit) id k4PLds3o067315 for perforce@freebsd.org; Thu, 25 May 2006 21:39:54 GMT (envelope-from jhb@freebsd.org) Date: Thu, 25 May 2006 21:39:54 GMT Message-Id: <200605252139.k4PLds3o067315@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to jhb@freebsd.org using -f From: John Baldwin To: Perforce Change Reviews Cc: Subject: PERFORCE change 97828 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: Thu, 25 May 2006 21:48:16 -0000 http://perforce.freebsd.org/chv.cgi?CH=97828 Change 97828 by jhb@jhb_mutex on 2006/05/25 21:39:16 Handle the easy case earlier so this function doesn't read so weird. Affected files ... .. //depot/projects/smpng/sys/kern/kern_linker.c#59 edit Differences ... ==== //depot/projects/smpng/sys/kern/kern_linker.c#59 (text+ko) ==== @@ -548,36 +548,39 @@ KLD_LOCK_ASSERT(); KLD_DPF(FILE, ("linker_file_unload: lf->refs=%d\n", file->refs)); - if (file->refs == 1) { - KLD_DPF(FILE, ("linker_file_unload: file is unloading," - " informing modules\n")); + + /* Easy case of just dropping a reference. */ + if (file->refs > 1) { + file->refs--; + return (0); + } + + + KLD_DPF(FILE, ("linker_file_unload: file is unloading," + " informing modules\n")); + + /* + * Inform any modules associated with this file. + */ + MOD_XLOCK; + for (mod = TAILQ_FIRST(&file->modules); mod; mod = next) { + next = module_getfnext(mod); + MOD_XUNLOCK; /* - * Inform any modules associated with this file. + * Give the module a chance to veto the unload. */ - MOD_XLOCK; - for (mod = TAILQ_FIRST(&file->modules); mod; mod = next) { - next = module_getfnext(mod); - MOD_XUNLOCK; + if ((error = module_unload(mod, flags)) != 0) { + KLD_DPF(FILE, ("linker_file_unload: module %p" + " vetoes unload\n", mod)); + return (error); + } else + MOD_XLOCK; + module_release(mod); + } + MOD_XUNLOCK; - /* - * Give the module a chance to veto the unload. - */ - if ((error = module_unload(mod, flags)) != 0) { - KLD_DPF(FILE, ("linker_file_unload: module %p" - " vetoes unload\n", mod)); - return (error); - } else - MOD_XLOCK; - module_release(mod); - } - MOD_XUNLOCK; - } - file->refs--; - if (file->refs > 0) - return (0); - for (ml = TAILQ_FIRST(&found_modules); ml; ml = nextml) { - nextml = TAILQ_NEXT(ml, link); + TAILQ_FOREACH_SAFE(ml, &found_modules, link, nextml) { if (ml->container == file) { TAILQ_REMOVE(&found_modules, ml, link); free(ml, M_LINKER);