cvs commit: src/sys/kern kern_proc.c

Garrett Wollman wollman at khavrinen.lcs.mit.edu
Wed Jun 9 16:29:51 GMT 2004


<<On Wed, 09 Jun 2004 18:20:00 +0200, "Poul-Henning Kamp" <phk at 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



More information about the cvs-src mailing list