PERFORCE change 97828 for review
John Baldwin
jhb at FreeBSD.org
Thu May 25 14:48:16 PDT 2006
http://perforce.freebsd.org/chv.cgi?CH=97828
Change 97828 by jhb at 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);
More information about the p4-projects
mailing list