diff options
author | alfred <alfred@FreeBSD.org> | 2000-12-01 06:59:18 +0000 |
---|---|---|
committer | alfred <alfred@FreeBSD.org> | 2000-12-01 06:59:18 +0000 |
commit | 7abbdcfd9b2708a74854f008e9526547466acb51 (patch) | |
tree | f4496a3ec12f7185760bcb63bcfbdc58afe0781f | |
parent | c2462a2bf1b0fd3bb773aea5b2b6cd94b61deaa5 (diff) | |
download | FreeBSD-src-7abbdcfd9b2708a74854f008e9526547466acb51.zip FreeBSD-src-7abbdcfd9b2708a74854f008e9526547466acb51.tar.gz |
Translate alfred to english.
Submitted by: bde
-rw-r--r-- | sys/kern/kern_resource.c | 60 |
1 files changed, 27 insertions, 33 deletions
diff --git a/sys/kern/kern_resource.c b/sys/kern/kern_resource.c index 24cecf1..a10c2c9 100644 --- a/sys/kern/kern_resource.c +++ b/sys/kern/kern_resource.c @@ -49,9 +49,9 @@ #include <sys/kernel.h> #include <sys/resourcevar.h> #include <sys/malloc.h> +#include <sys/mutex.h> #include <sys/proc.h> #include <sys/time.h> -#include <sys/mutex.h> #include <vm/vm.h> #include <vm/vm_param.h> @@ -701,7 +701,8 @@ uicreate(uid) struct uidinfo *uip; mtx_assert(&uihashtbl_mtx, MA_OWNED); - MALLOC(uip, struct uidinfo *, sizeof(*uip), M_UIDINFO, M_WAITOK|M_ZERO); + MALLOC(uip, struct uidinfo *, sizeof(*uip), M_UIDINFO, + M_WAITOK | M_ZERO); LIST_INSERT_HEAD(UIHASH(uid), uip, ui_hash); uip->ui_uid = uid; mtx_init(&uip->ui_mtx, "uidinfo struct", MTX_DEF); @@ -709,8 +710,8 @@ uicreate(uid) } /* - * find or allocate a struct uidinfo for a particular uid - * increases refcount on uidinfo struct returned. + * Find or allocate a struct uidinfo for a particular uid. + * Increase refcount on uidinfo struct returned. * uifree() should be called on a struct uidinfo when released. */ struct uidinfo * @@ -729,11 +730,11 @@ uifind(uid) } /* - * place another refcount on a uidinfo struct + * Place another refcount on a uidinfo struct. */ void uihold(uip) -struct uidinfo *uip; + struct uidinfo *uip; { mtx_enter(&uip->ui_mtx, MTX_DEF); @@ -741,52 +742,45 @@ struct uidinfo *uip; mtx_exit(&uip->ui_mtx, MTX_DEF); } -/* - * subtract one from the refcount in the struct uidinfo, if 0 free it - * since uidinfo structs have a long lifetime we use a +/*- + * Since uidinfo structs have a long lifetime, we use an * opportunistic refcounting scheme to avoid locking the lookup hash * for each release. * - * if the refcount hits 0 we need to free the structure + * If the refcount hits 0, we need to free the structure, * which means we need to lock the hash. - * optimal case: - * After locking the struct and lowering the refcount, we find - * that we don't need to free, simply unlock and return - * suboptimal case: - * refcount lowering results in need to free, bump the count + * Optimal case: + * After locking the struct and lowering the refcount, if we find + * that we don't need to free, simply unlock and return. + * Suboptimal case: + * If refcount lowering results in need to free, bump the count * back up, loose the lock and aquire the locks in the proper - * order to try again. + * order to try again. */ void uifree(uip) - struct uidinfo *uip; + struct uidinfo *uip; { - /* - * try for optimal, recucing the refcount doesn't make us free it. - */ + /* Prepare for optimal case. */ mtx_enter(&uip->ui_mtx, MTX_DEF); + if (--uip->ui_ref != 0) { mtx_exit(&uip->ui_mtx, MTX_DEF); return; } - /* - * ok, we need to free, before we release the mutex to get - * the lock ordering correct we need to - * backout our change to the refcount so that no one else - * races to free it. - */ + + /* Prepare for suboptimal case. */ uip->ui_ref++; mtx_exit(&uip->ui_mtx, MTX_DEF); - - /* get the locks in order */ mtx_enter(&uihashtbl_mtx, MTX_DEF); mtx_enter(&uip->ui_mtx, MTX_DEF); + /* - * it's possible that someone has referenced it after we dropped the - * initial lock, if so it's thier responsiblity to free it, but - * we still must remove one from the count because we backed out - * our change above. + * We must subtract one from the count again because we backed out + * our initial subtraction before dropping the lock. + * Since another thread may have added a reference after we dropped the + * initial lock we have to test for zero again. */ if (--uip->ui_ref == 0) { LIST_REMOVE(uip, ui_hash); @@ -802,9 +796,9 @@ uifree(uip) FREE(uip, M_UIDINFO); return; } + mtx_exit(&uihashtbl_mtx, MTX_DEF); mtx_exit(&uip->ui_mtx, MTX_DEF); - return; } /* |