cvs commit: src/sys/kern kern_proc.c

Garrett Wollman wollman at
Wed Jun 9 16:29:51 GMT 2004

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

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

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


More information about the cvs-src mailing list