Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 9 Jun 2004 12:29:49 -0400 (EDT)
From:      Garrett Wollman <wollman@khavrinen.lcs.mit.edu>
To:        "Poul-Henning Kamp" <phk@phk.freebsd.dk>
Cc:        cvs-all@FreeBSD.ORG
Subject:   Re: cvs commit: src/sys/kern kern_proc.c 
Message-ID:  <200406091629.i59GTnCx052623@khavrinen.lcs.mit.edu>
In-Reply-To: <55929.1086798000@critter.freebsd.dk>
References:  <20040609.100413.118633043.imp@bsdimp.com> <55929.1086798000@critter.freebsd.dk>

next in thread | previous in thread | raw e-mail | index | archive | help
<<On Wed, 09 Jun 2004 18:20:00 +0200, "Poul-Henning Kamp" <phk@phk.freebsd.dk> said:

> The way to fix this is to make sure that the test for zero-ness
> is done on the result of our own decrement operation:

> 	LOCK(foo->lock)
> 	i = --foo->refcount;
> 	UNLOCK(foo->lock)
> 	if (i == 0)
> 		destroy(foo);

I think it's clearer if you write:

	LOCK(foo->lock);
	if (--foo->refcount == 0)
		destroy(foo);	/* expects a locked foo */
	else
		UNLOCK(foo);

...and also a bit harder to mess up in maintenance (particularly if
destroy() asserts that the lock is held).

-GAWollman



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200406091629.i59GTnCx052623>