diff options
| -rw-r--r-- | sys/kern/kern_resource.c | 15 | ||||
| -rw-r--r-- | sys/sys/resourcevar.h | 5 |
2 files changed, 4 insertions, 16 deletions
diff --git a/sys/kern/kern_resource.c b/sys/kern/kern_resource.c index b70b97f5b720..cb5b73d2f005 100644 --- a/sys/kern/kern_resource.c +++ b/sys/kern/kern_resource.c @@ -48,6 +48,7 @@ __FBSDID("$FreeBSD$"); #include <sys/malloc.h> #include <sys/mutex.h> #include <sys/proc.h> +#include <sys/refcount.h> #include <sys/resourcevar.h> #include <sys/sched.h> #include <sys/sx.h> @@ -901,8 +902,7 @@ lim_alloc() struct plimit *limp; limp = malloc(sizeof(struct plimit), M_PLIMIT, M_WAITOK); - limp->pl_refcnt = 1; - limp->pl_mtx = mtx_pool_alloc(mtxpool_sleep); + refcount_init(&limp->pl_refcnt, 1); return (limp); } @@ -911,9 +911,7 @@ lim_hold(limp) struct plimit *limp; { - LIM_LOCK(limp); - limp->pl_refcnt++; - LIM_UNLOCK(limp); + refcount_acquire(&limp->pl_refcnt); return (limp); } @@ -922,14 +920,9 @@ lim_free(limp) struct plimit *limp; { - LIM_LOCK(limp); KASSERT(limp->pl_refcnt > 0, ("plimit refcnt underflow")); - if (--limp->pl_refcnt == 0) { - LIM_UNLOCK(limp); + if (refcount_release(&limp->pl_refcnt)) free((void *)limp, M_PLIMIT); - return; - } - LIM_UNLOCK(limp); } /* diff --git a/sys/sys/resourcevar.h b/sys/sys/resourcevar.h index 2697b66a4cbe..57d0fe73b336 100644 --- a/sys/sys/resourcevar.h +++ b/sys/sys/resourcevar.h @@ -78,13 +78,8 @@ struct pstats { struct plimit { struct rlimit pl_rlimit[RLIM_NLIMITS]; int pl_refcnt; /* number of references */ - struct mtx *pl_mtx; }; -#define LIM_LOCK(lim) mtx_lock((lim)->pl_mtx) -#define LIM_UNLOCK(lim) mtx_unlock((lim)->pl_mtx) -#define LIM_LOCK_ASSERT(lim, f) mtx_assert((lim)->pl_mtx, (f)) - /*- * Per uid resource consumption * |
