Date: Thu, 25 May 2006 21:39:54 GMT From: John Baldwin <jhb@FreeBSD.org> To: Perforce Change Reviews <perforce@freebsd.org> Subject: PERFORCE change 97828 for review Message-ID: <200605252139.k4PLds3o067315@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
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);
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200605252139.k4PLds3o067315>