Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 17 Apr 2002 12:27:47 -0700 (PDT)
From:      Julian Elischer <julian@elischer.org>
To:        John Baldwin <jhb@FreeBSD.org>
Cc:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   Re: PERFORCE change 9921 for review
Message-ID:  <Pine.BSF.4.21.0204171224590.97636-100000@InterJet.elischer.org>
In-Reply-To: <200204171801.g3HI1Id36075@freefall.freebsd.org>

next in thread | previous in thread | raw e-mail | index | archive | help


On Wed, 17 Apr 2002, John Baldwin wrote:

> http://people.freebsd.org/~peter/p4db/chv.cgi?CH=9921
> 
> Change 9921 by jhb@jhb_laptop on 2002/04/17 11:00:44
> 
> 	Only malloc newprocsig if we need it.  To make this nicer we need
> 	a procsig_alloc/hold/free(drop?)/dup/shared.  At some point I would
> 	like a standard naming scheme for all our refcounted objects as
> 	above.  Note that if _alloc() sets the refcount appropriately, then
> 	it won't need to use separate drop/free routines.   I also would
> 	like for us to use common names for all these refcount operations.

Very true..
In netgraph I use:
{obj}_ref() (add a reference)
{obj}_unref() (decrement and maybe free)
{obj}_new() (returns with one reference preallocated
for the caller to use.)


> 
> Affected files ...
> 
> ... //depot/projects/smpng/sys/kern/kern_exec.c#34 edit
> 
> Differences ...
> 
> ==== //depot/projects/smpng/sys/kern/kern_exec.c#34 (text+ko) ====
> 
> @@ -134,7 +134,7 @@
>  	struct vattr attr;
>  	int (*img_first)(struct image_params *);
>  	struct pargs *oldargs, *newargs = NULL;
> -	struct procsig *newprocsig = NULL;
> +	struct procsig *oldprocsig, *newprocsig;
>  	struct vnode *tracevp = NULL, *textvp = NULL;
>  
>  	imgp = &image_params;
> @@ -299,8 +299,6 @@
>  	/*
>  	 * Malloc things before we need locks.
>  	 */
> -	MALLOC(newprocsig, struct procsig *, sizeof(struct procsig),
> -	    M_SUBPROC, M_WAITOK);
>  	newcred = crget();
>  	i = imgp->endargs - imgp->stringbase;
>  	if (ps_arg_cache_limit >= i + sizeof(struct pargs))
> @@ -318,10 +316,15 @@
>  	PROC_LOCK(p);
>  	mp_fixme("procsig needs a lock");
>  	if (p->p_procsig->ps_refcnt > 1) {
> -		bcopy(p->p_procsig, newprocsig, sizeof(*newprocsig));
> -		p->p_procsig->ps_refcnt--;
> +		oldprocsig = p->p_procsig;
> +		PROC_UNLOCK(p);
> +		MALLOC(newprocsig, struct procsig *, sizeof(struct procsig),
> +		    M_SUBPROC, M_WAITOK);
> +		bcopy(oldprocsig, newprocsig, sizeof(*newprocsig));
> +		newprocsig->ps_refcnt = 1;
> +		oldprocsig->ps_refcnt--;
> +		PROC_LOCK(p);
>  		p->p_procsig = newprocsig;
> -		p->p_procsig->ps_refcnt = 1;
>  		if (p->p_sigacts == &p->p_uarea->u_sigacts)
>  			panic("shared procsig but private sigacts?");
>  
> @@ -458,8 +461,6 @@
>  	/*
>  	 * Free any resources malloc'd earlier that we didn't use.
>  	 */
> -	if (newprocsig != NULL)
> -		FREE(newprocsig, M_SUBPROC);
>  	if (newcred == NULL)
>  		crfree(oldcred);
>  	else
> 


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe p4-projects" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.BSF.4.21.0204171224590.97636-100000>