diff --git a/sys/kern/kern_proc.c b/sys/kern/kern_proc.c index 308c2e96b555..64745698e9fd 100644 --- a/sys/kern/kern_proc.c +++ b/sys/kern/kern_proc.c @@ -43,6 +43,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include @@ -90,7 +91,6 @@ struct proclist allproc; struct proclist zombproc; struct sx allproc_lock; struct sx proctree_lock; -struct mtx pargs_ref_lock; struct mtx ppeers_lock; uma_zone_t proc_zone; uma_zone_t ithread_zone; @@ -109,7 +109,6 @@ procinit() sx_init(&allproc_lock, "allproc"); sx_init(&proctree_lock, "proctree"); - mtx_init(&pargs_ref_lock, "struct pargs.ref", NULL, MTX_DEF); mtx_init(&ppeers_lock, "p_peers", NULL, MTX_DEF); LIST_INIT(&allproc); LIST_INIT(&zombproc); @@ -1090,7 +1089,7 @@ pargs_alloc(int len) MALLOC(pa, struct pargs *, sizeof(struct pargs) + len, M_PARGS, M_WAITOK); - pa->ar_ref = 1; + refcount_init(&pa->ar_ref, 1); pa->ar_length = len; return (pa); } @@ -1108,9 +1107,7 @@ pargs_hold(struct pargs *pa) if (pa == NULL) return; - PARGS_LOCK(pa); - pa->ar_ref++; - PARGS_UNLOCK(pa); + refcount_acquire(&pa->ar_ref); } void @@ -1119,12 +1116,8 @@ pargs_drop(struct pargs *pa) if (pa == NULL) return; - PARGS_LOCK(pa); - if (--pa->ar_ref == 0) { - PARGS_UNLOCK(pa); + if (refcount_release(&pa->ar_ref)) pargs_free(pa); - } else - PARGS_UNLOCK(pa); } /* diff --git a/sys/sys/proc.h b/sys/sys/proc.h index 0bbc86799df3..40275bc8c6be 100644 --- a/sys/sys/proc.h +++ b/sys/sys/proc.h @@ -806,10 +806,6 @@ MALLOC_DECLARE(M_ZOMBIE); curthread->td_pflags &= ~TDP_NOSLEEPING; \ } while (0) -/* Lock and unlock process arguments. */ -#define PARGS_LOCK(p) mtx_lock(&pargs_ref_lock) -#define PARGS_UNLOCK(p) mtx_unlock(&pargs_ref_lock) - #define PIDHASH(pid) (&pidhashtbl[(pid) & pidhash]) extern LIST_HEAD(pidhashhead, proc) *pidhashtbl; extern u_long pidhash; @@ -820,7 +816,6 @@ extern u_long pgrphash; extern struct sx allproc_lock; extern struct sx proctree_lock; -extern struct mtx pargs_ref_lock; extern struct mtx ppeers_lock; extern struct ksegrp ksegrp0; /* Primary ksegrp in proc0. */ extern struct proc proc0; /* Process slot for swapper. */